Skip to content
Miriam McMahon edited this page Apr 27, 2023 · 5 revisions

Description

The switch statement allows a different set of commands to be executed, depending on the value of a variable. If the value of the variable does not match any of the listed 'case' values, then a default set of commands is executed.

Parameters

Parameter Name Description Type Resolved Type Required
MatchValue A variable or expression to compare with the list of cases Value String Yes
Cases An array of CaseBlocks, see below. The case blocks are evaluated in order and the first one that matches is executed. Array Array Yes
DefaultCase The block of commands to be executed if no match was found Do Block Do Block No

Types

CaseBlock

Parameter Name Description Type Resolved Type Required
CaseValue The value to compare against the MatchValue. This should resolve to a string or a regular expression. Value String Yes
Do The list of commands to be executed if this CaseValue matches MatchValue. Do Block Do Block Yes

Examples

Example:

{
  "Switch": {
    "MatchValue": "%ReturnStatus%",
    "Cases": [
      {
        "CaseValue": "(CHECKSYS=[1-9]+.*)|(Permission denied)",
        "Do": [
          {
            "Throw": { "Value": "Insufficent rights" }
          }
        ]
      },
      {
        "CaseValue": "error: minimum password length is",
        "Do": [
          {
            "Throw": { "Value": "password is too short" }
          }
        ]
      },
      {
        "CaseValue": "error: maximum password length is",
        "Do": [
          {
            "Throw": { "Value": "password is too long" }
          }
        ]
      },
      {
        "CaseValue": "error: .*",
        "Do": [
          {
            "Throw": { "Value": "an error occurred: %ReturnStatus%" }
          }
        ]
      }
    ],
    "DefaultCase": {
      "Do": [
        {
          "Comment": { "Text": "Password Length is ok" }
        },
        {
          "Return": { "Value": true }
        }
      ]
    }
  }
}