makes icon indicating copy to clipboard operation
makes copied to clipboard

Select option widget

Open blaggacao opened this issue 3 years ago • 6 comments

since the following was a bit contrived to find, maybe we can add a simple select option widget for semi-interactive runbooks...


function select_iogo_job {
  local string=""
  info "Please select the nomad job(s) that you deployed with iogo"
  PS3="Please enter: "
  select opt in routing front back signer rabbit patroni Ok Abort; do
      case $REPLY in
          1 | 2 | 3 | 4 | 5 | 6)
              string="${string}-$opt"
              ;;
          7)
              break
              ;;
          8)
              info Aborting
              exit
              ;;
          *) echo "invalid node $REPLY";;
      esac
  done
  echo "$string"
}

Any ideas?

blaggacao avatar Sep 21 '21 23:09 blaggacao

We currently have these two

  • https://github.com/fluidattacks/makes#tobasharray
  • https://github.com/fluidattacks/makes#tobashmap I suppose we can write a third that does something like this:
let
   mySelect = toBashSelect {
    prompt = "pick whatever you want";
    options = [ "routing" "front" ... ];
   };
in
{ ... }
source "${envMySelect}/template" local selected_options  # derivations
source __argMySelect__/template local selected_options  # templates

echo "${selected_options[@]}"  # routing front .., whatever the user selected during the prompt

break and abort are automatically injected

kamadorueda avatar Sep 22 '21 00:09 kamadorueda

also maybe toBashSelectMany, toBashSelectOne

kamadorueda avatar Sep 22 '21 00:09 kamadorueda

or toBashSelect and a few options like:

  • allowMultipleAnswers ? bool
  • allowRepeatedAnswers ? bool
  • minimumSelections ? int

kamadorueda avatar Sep 22 '21 00:09 kamadorueda

The last suggestion seems best! Great conceptualization, thanks! I was a bit struggling on this one and I figured this might be the point where users start asking for a proper scripting language. My hope is we can extend bash's reach just another bit for most devops use cases...

blaggacao avatar Sep 22 '21 01:09 blaggacao

is there a language you have in mind that covers all the use cases we have now + being a "proper" scripting language?

kamadorueda avatar Sep 22 '21 01:09 kamadorueda

Actually any language has the same problem: you can't paste them 1-by-1 on any dev's cli.

That's probably the single biggest advantage with bash in this devops case...

blaggacao avatar Sep 22 '21 01:09 blaggacao