Skip to content

How to write an advanced cbf script

Joshua Vernon edited this page Jan 3, 2020 · 2 revisions

Advanced scripts are made up of option's, command's, variables, message's and directory's

  1. The first tag is required and is the scripts name
  2. options tags are used to store lists of more options or command's
  3. command tags are used to store one or many strings containing shell commands
  4. variables tags are used to prompt the user for variables to be replaced in a command
  5. message tags are used to store messages that are printed to stdout when an option or command is selected
  6. directory tags are used to set where a command should be run. When a command is run, CBF recursively searches for the commands set directory or closest set parent directory tag

Using yaml

example-project:
    message: "Run, build or test example project?"
    directory: "~/projects/example"
    options:
        run:
            message: "Running example project..."
            command: "yarn start"
        build:
            directory: "~/projects/example/src"
            message: "Building example project..."
            command: "yarn install"
        test:
            message: "Run unit or integration tests?"
            options:
                unit:
                    message: "Running example project unit tests"
                    command: "yarn test:unit"
                integration:
                    message: "Running example project integration tests"
                    command: "yarn test:integration"

Using json

{
  "example-project": {
    "message": "Run, build or test example project?",
    "directory": "~/projects/example",
    "options": {
      "run": {
        "message": "Running example project...",
        "command": "yarn start"
      },
      "build": {
        "directory": "~/projects/example/src",
        "message": "Building example project...",
        "command": "yarn install"
      },
      "test": {
        "message": "Run unit or integration tests?",
        "options": {
          "unit": {
            "message": "Running example project unit tests",
            "command": "yarn test:unit"
          },
          "integration": {
            "message": "Running example project integration tests",
            "command": "yarn test:integration"
          }     
        }
      }
    }
  }
}

You can find more example advanced scripts here.

Usage

Save it to cbf

$ cbf -s example-project.json

Run it with cbf

$ cbf -r example-project

Check out cbf's 🦥 site to get started!

Clone this wiki locally