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

feat(prompts): add ability for tasks to prompt user pre execution #1163

Merged
merged 4 commits into from
Jun 4, 2023

Conversation

MaxCheetham
Copy link
Contributor

fixes #100

Adding a Prompt filed to allow users to set a message to be shown before task excecution.
Also added an early exit code (205) for when this happens

Copy link
Member

@andreynering andreynering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MaxCheetham, thanks for your contribution!

A few things needs to be adjusted before this is ready to be merged.

  1. I noticed a bug where the prompt is not really asked if the task is called indirectly.
version: '3'

tasks:
  default:
    cmds:
      - task: show-prompt

  show-prompt:
    prompt: Are you sure?
    cmds:
      - echo Hi

Calling task show-prompt asks confirmation, but task default not. I believe it should be shown on both cases.

  1. A --yes (alias -y) might be needed here, otherwise it would be impossible to ask run these tasks on a CI, for example. This flag would bypass the confirmation and run anyway.

@andreynering
Copy link
Member

A section on the Usage page in the documentation could be interesting as well.

Another contributor wrote this for an implementation that end up not being merged. You could use that as inspiration.

@MaxCheetham
Copy link
Contributor Author

MaxCheetham commented May 24, 2023

Hey @andreynering, thanks for catching that bug, and also the request for the enchancements.

  • I added an AssumeYes flag (--yes | -y)
  • Fixed the bug you found by moving the prompting closer to task execution
    • this has the (upside / downside?) of meaning that tasks can run pre-prompt if they themselves have no prompt. A possible extension to this could be a skippable bool in the task file that could allow for a prompted task that was denied to be skipped, however, I felt like the implacations of this change would be too big to include in this PR, and would merit some descussion before hand.
  • I added a section to the Usage docs, I will be the first to admit that my technical writing isn't fantastic, so any advise on wording / structure would be taken onboard gladly. 🚀

@andreynering andreynering merged commit f815ce2 into go-task:main Jun 4, 2023
andreynering added a commit that referenced this pull request Jun 4, 2023
@andreynering
Copy link
Member

Thanks @MaxCheetham!

I did a few improvements on 44aaec8. The most important one being a fix that forces the task to fail on a non-terminal environment (imagine CI). Without this, the task would hang forever waiting for someone to type y, but that would be impossible on these environments.

@pd93 pd93 mentioned this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A warning/confirm field that shows a confirm prompt before proceeding
2 participants