Configure Inputs

In this section, you will find information about a formula config.json file

What is the config.json file?

The config.json file contains the formula’s input parameters. It allows the CLI to know what data to ask the user when he runs the command in the terminal to process the formula correctly.

These input parameters are made up of the following fields:

  • dockerImageBuilder: A docker image builder (according to the programming language chose at the formula creation).
  • dockerVolumes: List of local volumes you want to mount in the docker run container.
  • inputs: The formula inputs parameters list.
  • requireLatestVersion: A boolean, indicating the need (or not) of the formula to run in the last available version of a repository.
{
  "dockerImageBuilder": "dockerImage",
  "dockerVolumes": [],
  "inputs": [],
  "requireLatestVersion": false,
}

Docker volume mapping configuration

For each volume that will be mapped, you must inform its origin and destination, using a colon ":" as a separator.

Example:

The source directory being /home/user-name/folder and the destination directory /mount/folder

{
    "dockerVolumes": [
        "/home/user-name/folder:/mount/folder"
    ],
}

Input parameter configuration

Each input parameter is composed of the following fields:

Mandatory fields

  • name: variable name to extract.

A good practice is to add a _RIT_ suffix to each input name to avoid having conflicts with local variables.

Example: rit_file_name –> RIT_FILE_NAME

  • type:
    • text (string).
    • bool (boolean).
    • password (hidden string on CLI).
    • multiselect list predefined values, it is possible to select multiple values (string).
    • credentials (specific type, check out more on use crendential as formula inputs).
    • dynamic (associated with the optional request_info field below).
    • path: enables the autocomplete to inform a path to a folder or a file (string).
  • label: text appearing on the CLI, asking for the input.

Input example with mandatory fields:

{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
}

Input example with the multiselect type:

{
      "label": "Choose one or more days: ",
      "name": "rit_days",
      "type": "multiselect",
      "required": true,
      "items": [
           "Monday",
           "Tuesday",
           "Wednesday",
           "Thursday",
           "Friday",
           "Saturday",
           "Friday"
      ]
}

Some observations regarding the multiselect type

  1. To select one of the options with the multiselect type,
  • Press the space key (the enter key will move to the next input, if any).
  1. The options selected in the multiselect type field will return a string with:
  • The options separated by pipe (|) and without space example: Monday | Wednesday | Friday
  1. Use the required field as true, otherwise, if no option is selected, the local variable will be saved as undefined.

Parameter example using the autocomplete type:

{
      "label": "Type the path to the folder with your file:",
      "name": "rit_path",
      "type": "path"
}

Optional fields

  • default: default input value (if value is null).
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "default": "Dennis"
}
  • required: Boolean that indicates if the input value is required or optional.
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "required": true
}
  • tutorial: Input helper message [? for help]
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "tutorial": "We are expecting you to write your name (ex: John)"
}
  • items: List of input variable options.
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "items": [
            "Dennis",
            "John",
            "Bill"
      ]
}
  • cache: Saves former input values.
    • active: If the cache is enabled or not.
    • qty: Amount of values to store.
    • newLabel: Text appearing on the CLI asking for new input.
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "cache": {
            "active": true,
            "qty": 5,
            "newLabel": "Type another name:"
      }
}

  • condition: It shows an input if the given condition succeeds.
    • variable: The variable name used on a previous input for comparison.
    • operator: A logical operator to compare. Supports ==, !=, <, >, <= and >=.
    • value: The desired value to compare to.
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "default": "Dennis"
},
{
      "condition": {
            "variable": "rit_name",
            "operator": "!=",
            "value": "Dennis"
      }
      "label": "What is your date of birth?",
      "name": "rit_date_of_birth",
      "type": "text",
}
  • pattern: Configure the input value validation.
    • regex: The regex pattern to validate the input.
    • mismatchText: An error message when the input doesn’t match the regex pattern.
{
      "label": "What is your age",
      "name": "rit_age",
      "type": "text",
      "pattern": {
            "regex": "[0-9]",
            "mismatchText": "Only a integer value is allowed here (ex: 20)"
      }
}
  • requestInfo: A configuration to get the dynamic input type.
    • url: An URL to consume a GET service that will return a list of objects.
    • jsonPath: A JSON path where the variable extracts a returned list for every object, see "jsonPath": $['user']['name'] (Check out how the JSON path works).
{
      "label": "Type your name:",
      "name": "rit_name",
      "type": "text",
      "requestInfo": {
            "url": "https://my-url.com",
            "jsonPath": $['user']['name']
      }
}

Conditional input example with Regex pattern:

"inputs": [
    {
      "label": "Select a system:",
      "name": "rit_system",
      "type": "text",
      "items": [
        "LINUX",
        "MACOS",
        "WINDOWS"
      ],
      "required": true,
      "tutorial": "Select a System from the list."
    },
    {
      "condition": {
        "variable":"rit_system",
        "operator":"==",
        "value":"LINUX"
      },
      "label": "Select a LINUX OS:",
      "name": "rit_linux_os",
      "type": "text",
      "items": [
        "UBUNTU",
        "FEDORA",
        "CENTOS"
      ],
      "pattern": {
        "regex": "UBUNTU|FEDORA|CENTOS",
        "mismatchText": "Invalid option"
      },
      "required": false,
      "tutorial": "Select an Linux Operating System from the list."
    }
  ]

Last modified October 29, 2021: Doc review (#161) (ef9c57d8)