Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two new argument types: checkbox and checklist #104

Open
ManuelFte opened this issue Feb 9, 2023 · 6 comments
Open

Two new argument types: checkbox and checklist #104

ManuelFte opened this issue Feb 9, 2023 · 6 comments

Comments

@ManuelFte
Copy link

ManuelFte commented Feb 9, 2023

I would like to suggest the addition of two new argument types which would be a checkbox and a list of checkboxes. These would be useful for functions that require verification or when the user can select several options rather than picking just one from a drop down menu.

I imagine that they could work like this:

checkbox

Returns a boolean. An example could be a button that reboots the server and where the checkbox prevents accidental clicks:

image

- title: Reboot server
  icon: ""
  shell: <code here>
  arguments:
    - title: Are you sure?
      name: verification
      type: checkbox

checklist

Returns an array of the options chosen. An example could be a backup script that allows you to choose the directories you want to back up:

image

- title: Backup Script
  icon: "💾"
  shell: <code here>
  arguments:
    - title: Directories to back up
      name: directories
      type: checklist
      choices:
        - title: Documents
          value: documents

        - title: Photos
          value: photos

        - title: Music
          value: music
    
        - title: Videos
          value: videos
@ManuelFte ManuelFte changed the title New argument type: checkbox Two new argument types: checkbox and checkboxlist Feb 9, 2023
@ManuelFte ManuelFte changed the title Two new argument types: checkbox and checkboxlist Two new argument types: checkbox and checklist Feb 9, 2023
@jamesread
Copy link
Collaborator

Hey @ManuelFte ,

Thanks for taking the time to write this up, and for investigating the extra effort for the examples - love that!

Let's coktijuecuour ideas into the design. I think we could break this design into a few types as you're alluding to;

  • checkbox - simply gives 1 / 0 depending on checked / unchecked. It could also be true / false - but 1 / 0 would be easier for bash scripts and any other language, rather than having to parse the text.
  • confirmation - this has come up before, it's more like a "dummy" argument that has to be ticked before OliveTin will execute the action. It's value when executed would always be 1 (and if it's unticked, execution should be cancelled with a logged error).
  • checklist - your proposal is fine, but we need to think about the format of the values passed through to any script; probably CSV makes the most sense here - "Apple, Chocolate Cake,Waffles". This is probably easily parsed by most languages. You'd refer to the value on the shell argument like: script.sh {{myChecklist}}

I can't think of any other design considerations right now, what do you think?

@ManuelFte
Copy link
Author

ManuelFte commented Feb 9, 2023

For the boolean, 1/0 definitely sounds better than true/false as strings.

What would be the difference between checkbox and confirmation?

CSV also sounds fine as the format for the array.

I have no more recommendations, happy to hear that this seems to be very smooth.

Edit: actually, I just thought on a suggestion: for the checklist, maybe an option to select all/select none would be a plus.

@jamesread
Copy link
Collaborator

What would be the difference between checkbox and confirmation?

checkbox would allow you to refer to values in the shell command; eg: {{ runAsRoot }}, or {{ hasTimer }}, whereas confirmation would be a special argument type that stops the execution entirely unless ticked.

Edit: actually, I just thought on a suggestion: for the checklist, maybe an option to select all/select none would be a plus.

This sounds sensible :-)


Now that I think the design looks complete, I'm going to try and capture these design choices as some sort of acceptance criteria for this feature. I've not done that before, but I think that's how we should be implementing features / changes in OliveTin. This is a nice small feature to test that out on :-)

@ManuelFte
Copy link
Author

checkbox would allow you to refer to values in the shell command; eg: {{ runAsRoot }}, or {{ hasTimer }}, whereas confirmation would be a special argument type that stops the execution entirely unless ticked.

Ohh, I get it. So in the practice, confirmation would be what you'd use for my example of the reboot button that requires verification or else the script won't run, while checkbox would be used when the script does run but it has to check if the user selected certain options.

Sounds good, it's a built-in feature to accomplish tasks like that of the example without having to write a function that does the verification, and that for shell instructions that are just one-liners it'd be ugly (the verification would be longer than the actual command, lol).

Now that I think the design looks complete, I'm going to try and capture these design choices as some sort of acceptance criteria for this feature. I've not done that before, but I think that's how we should be implementing features / changes in OliveTin. This is a nice small feature to test that out on :-)

Nice, glad that my suggestion was useful for this, hahaha. Looking forward to see the feature.

@jamesread
Copy link
Collaborator

Just had a thought, it may be nice to be able to set string values;

actions:
  - title: remove files
    shell: rm {{ useForce }} /mnt/Downloads/
    arguments:
      - name: useForce
        type: checkbox
        valueIfChecked: "-rf"

@jamesread
Copy link
Collaborator

Confirmation checkboxes were added based on this suggestion - I just didn't update this issue! https://docs.olivetin.app/confirmation.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants