input_dropdown.adoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [#arg-dropdowns]
  2. = Input: Dropdowns
  3. Predefined choices are normally the safest type of arguments, because users are limited to only enter values that you specify.
  4. [source,yaml]
  5. ----
  6. actions:
  7. - title: Print a message
  8. icon: smile
  9. shell: echo "{{ message }}"
  10. arguments:
  11. - name: message
  12. description: The message you want to print out.
  13. choices:
  14. - title: Hello
  15. value: Hello there!
  16. - title: Goodbye
  17. value: Aww, goodbye. :-(
  18. ----
  19. Note that when predefined choices are used, the argument type is ignored.
  20. This is what it looks like in the web interface;
  21. image::args4.png[]
  22. Then finally, when you execute this command, it would look something like this (remember that this is just a basic "echo" command).
  23. image::args-choices-exec.png[]
  24. In the logs, you can then click on the log entry link to open the results;
  25. image::args3.png[]
  26. [#args-dropdown-entities]
  27. == Using Entities in Dropdowns
  28. Dropdowns can also be populated with a list of entities, like this;
  29. [source,yaml]
  30. .`config.yaml`
  31. ----
  32. actions:
  33. - title: restart container
  34. shell: 'docker restart {{ containerToRestart }}'
  35. arguments:
  36. - name: containerToRestart
  37. entity: container
  38. title: 'Select Container'
  39. choices:
  40. - value: '{{ container.Names }}'
  41. title: '{{ container.Names }}'
  42. entities:
  43. - file: entities/containers.json
  44. name: container
  45. ----
  46. This is what it looks like in the web interface;
  47. image::args-choices-entities.png[]
  48. include::partial$args/reject-null.adoc[]
  49. == Default values
  50. Dropdown arguments can also have default values. This is done by adding a `default` key to the argument definition.
  51. include::partial$config-start.adoc[]
  52. ----
  53. actions:
  54. - title: "Print your favorite movie"
  55. shell: echo '{{ movie }} is amazing'
  56. arguments:
  57. - name: movie
  58. choices:
  59. - value: "Star Wars"
  60. - value: "Star Trek"
  61. - value: "The Matrix"
  62. default: "Star Trek"
  63. ----