Prompts

GeneSystem is primarily designed to be an interactive installer, prompts provide a way to ask the user for information before a step proceeds.

prompts accepts an array of prompt objects. A prompt object requires the following key value pairs:

  • prompt the message you want to display
  • var the variable you want to assign the response to

When the install or remove commands get to the step, the installation will stop and the user will be asked for input using the message provided in the prompt key/value pair. The order upon which the prompts are asked is in the order specified in the array, so it is possible to ask follow up questions.

The response will then be assigned to a variable which can be interpolated into a subsequent command. Interpolation should be done in handlebars syntax (i.e. {{variable_name}})

Below is an example of a manifest that both defines a prompt and uses the user’s response:

{
  "name": "say hello",
  "exe": {
    "install": {
      "prompts": [
        {
          "prompt": "Please enter your name",
          "var": "name"
        }
      ],
      "cmd": [
        "echo \"hello {{ name }}\""
      ]
    }
  },
  "tags": "example step"
}

This is useful if you require the user to enter a secret into file which can be achieved with a step like this:

{
      "name": "set password",
      "exe": {
        "install": {
          "skip": "[[ -n $PASSWORD ]]",
          "prompts": [
            {
              "prompt": "Please retrieve your password from lastpass and enter it here",
              "var": "password"
            },
          ],
          "cmd": [
            "echo 'export PASSWORD=\"{{ password }}\"' >> $HOME/.zshrc"
          ],
        },
      },
      "tags": "set password"
    },

Or perhaps you might want to use it to prompt a user to take an action that the remainder of the script requires:

{
      "name": "copy secret file into repository",
      "exe": {
        "install": {
          "skip": "[ -f $HOME/Code/andrewbigger/application/config/secrets.yml ]",
          "prompts": [
            {
              "prompt": "Please create a run `touch $HOME/Code/andrewbigger/application/config/secrets.yml`\n\n PRESS ANY KEY TO CONTINUE",
              "var": "noop"
            },
            {
              "prompt": "Please copy the contents of secrets.yml from lastpass into $HOME/Code/andrewbigger/application/config/secrets.yml\n\n PRESS ANY KEY TO CONTINUE",
              "var": "noop"
            },
          ],
          "cmd": []
        },
      },
      "tags": "create application secrets.yml"
    },