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

Add command-level and task-level warning #352

Closed

Conversation

parkerduckworth
Copy link

@parkerduckworth parkerduckworth commented Jul 20, 2020

Hey @andreynering, just saw your comment on issue #100 regarding the pending upstream ability to pass a -p flag to read. Coincidentally, I just finished writing this patch before your reply.

I understand that mdvan/sh#551 will clear up the ability to add a prompt, but I think that having an explicit warning option at both task and command levels may improve this tool. What do you think?

Here is how warning can be used at both levels:

version: '3'

tasks:
  example-task:
    desc: An example
    warning: Are you sure you want to run this task?
    cmds:
      - cmd: rm -rf /important-files
        warning: Are you sure you want to run this command?
      - rm -rf /unimportant-files

Declining to run a command with a command-level warning results in the command being skipped, and the rest of the commands in the task (without warnings) will run unhindered.

I know you will have this project's best interest in mind. Thanks for considering this feature!

@andreynering andreynering added type: feature A new feature or functionality. v3 labels Jul 20, 2020
@andreynering
Copy link
Member

Hi @parkerduckworth, thanks for the PR! 🙂

The code seems simple enough to be worth adding this. I'll probably check this in another day, though...

In the meantime, can you change the base branch from master to v3 and rebase?

@parkerduckworth
Copy link
Author

Absolutely!

@parkerduckworth parkerduckworth changed the base branch from master to v3 July 20, 2020 14:16
@parkerduckworth
Copy link
Author

Ok @andreynering , everything looks to be in order!

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 @parkerduckworth,

Sorry for the wait, been busy recently...

Some comments so far:

  • I think that prompt may be a better name than warning. What do you think?
  • I think it's a bit inconsistent that command prompts skips the command while task prompts makes it error. I think both should have the same behavior, and I believe the right behavior would be to skip the task. Sounds good?
  • Many CLI tools have a -y argument to bypass prompts and execute then without asking. This is important to allow executing these commands on CI, for example.
  • [Optional] A small section on the documentation about this would be nice. But if you don't want to do it, I'll after the merge

@parkerduckworth
Copy link
Author

@andreynering no worries, life is to be lived!


I think that prompt may be a better name than warning. What do you think?

I think that prompt offers more flexibility! At the moment, these changes append a yes/no option at the end of the supplied warning, i.e. fmt.Printf("%s (y/N): ", warning). If we go with prompt, this should probably change to print only the provided prompt (fmt.Printf("%s: ", prompt), as a prompt may often require more than a yes or no answer.

So maybe an example would be like this:

tasks:
  example-task:
    desc: An example
    prompt: Are you sure you want to run this task? (y/N)

I think the answer depends on whether or not we want more flexibility here. You have obviously spent much more time than I working with this codebase, so I would happily agree with your preference.


I think it's a bit inconsistent that command prompts skips the command while task prompts makes it error. I think both should have the same behavior, and I believe the right behavior would be to skip the task. Sounds good?

Excellent! So shall it be.


Many CLI tools have a -y argument to bypass prompts and execute then without asking. This is important to allow executing these commands on CI, for example.

I agree! We should provide this affordance as well.


[Optional] A small section on the documentation about this would be nice. But if you don't want to do it, I'll after the merge

Ha! I would be more than happy to write up the docs for this!!


If you are good with all my above remarks, I will make these changes and push them up.

@andreynering
Copy link
Member

andreynering commented Aug 4, 2020

Thinking better, let's keep warning for a matter of clarity since it'll only have two options (yes and no, not sure how we'd support more)

On the other points, I think we agree about them, so feel free to proceed =)

@parkerduckworth
Copy link
Author

Requested changes have been made 👍

@parkerduckworth
Copy link
Author

Hey @andreynering, you mind sharing why this was closed?

@andreynering
Copy link
Member

@parkerduckworth Sorry, this was a mistake

For some reason GitHub closed many PRs after merging #220

Reopening...

@andreynering andreynering reopened this Aug 16, 2020
@andreynering andreynering changed the base branch from v3 to master August 16, 2020 23:51
@parkerduckworth
Copy link
Author

Hello @andreynering ! Is this feature still going to be merged?

@parkerduckworth
Copy link
Author

Hey @andreynering , this is actually no longer necessary, as I was able to get read -p flag support merged into https://github.com/mvdan/sh with this PR.

Any chance we can cut a new release with the updated mvdan/sh dependency to allow us to pass in -p to read?

Thank you!

@pd93 pd93 removed the v3 label Oct 15, 2022
@andreynering
Copy link
Member

@parkerduckworth Sorry for not responding to you all this time. Life happens.

Good to hear that the read -p works for you. Thanks for your contribution on mvdan/sh#722 as well.

@parkerduckworth
Copy link
Author

@andreynering apology not necessary 🙂 Hope all is well mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature or functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants