Advertisement
smeech

Swap outputs

Dec 5th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.26 KB | None | 0 0
  1. # The following snippet produces a choice Form and then uses
  2. # a shell script to swap its input for different values.
  3. # It's an alternative to label: & id: use, that
  4. # enables the use of the choice: drop-down facility
  5.  
  6.   - trigger: :test
  7.     replace: "{{output}}"
  8.     vars:
  9.       - name: form1
  10.         type: form
  11.         params:
  12.           layout: "[[choices]]"
  13.           fields:
  14.             choices:
  15.               type: choice
  16.               values: |
  17.                one
  18.                 two
  19.                 three
  20.               default: one
  21.       - name: output
  22.         type: shell
  23.         params:
  24.           shell: bash
  25.           cmd: |
  26.            case $"{{form1.choices}}" in
  27.               one)
  28.                 output=four ;;
  29.               two)
  30.                 output=five ;;
  31.               three)
  32.                 output=six ;;
  33.             esac
  34.             echo $output
  35.  
  36. # For Python, replace the "output" block with:
  37.       - name: output
  38.         type: script
  39.         params:
  40.           args:
  41.            - python
  42.             - -c
  43.             - |
  44.              choices = {
  45.                   "one": "four",
  46.                   "two": "five",
  47.                   "three": "six"
  48.               }
  49.               print(choices.get("{{form1.choices}}", ""))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement