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

task confirmation #2050

Open
jdx opened this issue May 10, 2024 · 4 comments
Open

task confirmation #2050

jdx opened this issue May 10, 2024 · 4 comments

Comments

@jdx
Copy link
Owner

jdx commented May 10, 2024

just has a really cool feature to provide confirmation dialogs for a dangerous task:

[confirm("Are you sure you want to delete everything?")]
delete-everything:
  rm -rf *

I'm thinking we could probably go beyond this by leveraging similar features in demand like choosing from different choices: https://github.com/jdx/demand

@roele
Copy link
Contributor

roele commented Jul 3, 2024

I toyed around a bit with this idea and tried to come up with an extensible way to define these user inputs.

VS Code also has something similar in this regards for tasks, allowing the user to define certain input types which can be used later in the task itself.

So one approach might be to have an inputs property taking an array of input's. Each input has an id with which it can be referenced later, a input_type, a title and a description. Maybe we need specific types for each input_type.

User inputs can then be mapped to prefixed environment variables to be used in the task scripts.

[tasks."confirm"]
inputs = [ 
    { id = "confirm", input_type = "confirm", title = "Do you really want to run this task?" },
]

[tasks."dowhatever"]
run = "echo 'Doing whatever...'"

[tasks."build"]
depends = [ "confirm", "dowhatever" ]
inputs = [
    { id = "success_msg", input_type = "input", title = "Input a build success message" }
]
run = [
  "echo 'Building...'",
  "echo \"Success: $MISE_INPUT_SUCCESS_MSG\";",
  "exit 0;"
]

[tasks."deploy"]
depends = [ "build"]
inputs = [ 
    { id = "target", input_type = "multiselect", title = "Where to deploy to?", options = ["Dev", "Stage", "Prod"]}
]
run = [
  "echo \"Deploying to $MISE_INPUT_TARGET...\";",
  "exit 0;"
]

A working example can be found in an early draft at #2348.

While this works for simple use cases, the major issue i see here is with the nature of parallel (non linear) task execution and interleaving output.

@jdx
Copy link
Owner Author

jdx commented Jul 10, 2024

Hmm, so I do like this idea, however I've had plans which might not be written down and are quite vague but essentially I want to tie usage completions and mise tasks together such that you would be able to define a usage spec on a task in order to get inputs. This would be a slightly different use-case but I feel it's similar enough that it conflicts.

What I potentially like about this is maybe "confirmation" could be a high-level thing like that?

Another completely different idea I had was to use tera templates inside of tasks as a way to define inputs, though confirmation doesn't make a lot of sense in that regard.

Perhaps though we're both overthinking this and maybe it could be as simple as "confirm = true"?

@roele
Copy link
Contributor

roele commented Jul 20, 2024

Yes you might be right about overthinking this. Nevertheless the issues stay the same and demand is not able to deal with the multithreading/interweaving nature of the console output in case of multiple parallel tasks asking for confirmation.

@jdx
Copy link
Owner Author

jdx commented Jul 20, 2024

No but I do work around that problem in mise via a mutex. Perhaps that mutex could just go into demand directly? I can’t think of a use-case where you would ever want multiple demand components simultaneously.

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

No branches or pull requests

2 participants