task icon indicating copy to clipboard operation
task copied to clipboard

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

Open ianwalter opened this issue 7 years ago • 7 comments
trafficstars

I think it would be cool if there was a way to specify a warning before executing commands in which the user may not fully understand the consequences. It could look like:

reset:
  desc: Reset environment from scratch
  warning: This will remove all data and environment customization. Are you sure you want to do this?

And then before executing task reset it would prompt the user with a confirm prompt that looks like:

This will remove all data and environment customization. Are you sure you want to do this? [y/N]

ianwalter avatar Mar 10 '18 14:03 ianwalter

Hi @ianwalter,

This is probably already possible somehow using bash inside a command.

I'll keep this open for discussion if this is worth implementing. It would not be hard.

andreynering avatar Mar 11 '18 19:03 andreynering

@andreynering That's a good point. I could use read and then conditionally execute a shell command based on the user's response. The only problem is that on confirm I want to execute a series of tasks. I could just create a new task and then execute something like task resetConfirmed but that would expose the command in help (and in the CLI) which is not really a good UX. Feel free to close this though if you want to prioritize being lean over UX.

ianwalter avatar Mar 13 '18 16:03 ianwalter

@ianwalter Take a look at the silent option, you can prevent a command to be printed.

I still consider to accept a patch for this, though.

andreynering avatar Mar 13 '18 22:03 andreynering

Hey @andreynering is this something still being considered?

Having this command in a cmds block fails to run:

cmds:
  - read -p "Display me as a prompt. Continue? (y/n)"

And produces this oddity:

read: invalid option "-p"

If you still think adding a warning or prompt block would be a good addition to this project I would gladly take on the task (😉) to write the patch.

parkerduckworth avatar Jul 09 '20 21:07 parkerduckworth

@parkerduckworth That should be possible once https://github.com/mvdan/sh/issues/551 is implemented upstream.

andreynering avatar Jul 20 '20 00:07 andreynering

Example prompt implemented with the dialog command in case someone needs a confirmation prompt until this feature is discussed.

version: '3'

tasks:

  confirm:
    desc: "Executes a dangerous command.."
    cmds:
      - |
        dheight=10 \
        ; dwidth=60 \
        ; dialog \
          --defaultno \
          --backtitle "Dangerous Command Title" \
          --yesno \
            "Do you really want to execute the dangerous command?" \
          ${dheight} \
          ${dwidth}
      - echo "Executing dangerous command."

AnonLibre avatar Jun 18 '21 09:06 AnonLibre

Hello @andreynering ,

I would like to contribute to the project and improve my Go skills

I think it is a good issue to start. Do you mind assigning it to me ?

My idea is to implement a function from Outf that return the string read from STDIN. I have two doubts:

  • Which kind of input? Buffered (need a CR) or unbuffered (like a keypress). I think to use buffered input so the user must press ENTER to confirm.

  • Where put the function? I think I put internal / logger.go even though it's not really a logging function (it ask a input from the terminal).

core-dev-crypto avatar Aug 20 '22 10:08 core-dev-crypto

Hey @andreynering is this something still being considered?

Having this command in a cmds block fails to run:

cmds:
  - read -p "Display me as a prompt. Continue? (y/n)"

And produces this oddity:

read: invalid option "-p"

If you still think adding a warning or prompt block would be a good addition to this project I would gladly take on the task (😉) to write the patch.

I know this is kind of necrothreading, but to be fair, the -p flag works for me, look:

image

wtfzambo avatar Mar 10 '23 16:03 wtfzambo

I know this is kind of necrothreading

Not really, this still hasn't been implemented and I think it can still add value to Task 😛 A couple of things have changed since this thread was last updated:


the -p flag works for me

Yep, mvdan/sh now supports read -p, so you should be able to use this just fine. Related:

  • https://github.com/go-task/task/issues/314
  • https://github.com/mvdan/sh/pull/722

I could just create a new task and then execute something like task resetConfirmed but that would expose the command in help (and in the CLI) which is not really a good UX.

We now have internal tasks which solves this.


Also a recent related discussion: #1033.

pd93 avatar Mar 10 '23 17:03 pd93