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

When prompting for a user yes/no answer, use a short [y/n] representation #181

Closed
christianrondeau opened this issue Mar 20, 2015 · 13 comments
Assignees
Milestone

Comments

@christianrondeau
Copy link
Contributor

Here is how yes/no/skip answers are displayed:

Do you want to run the script?
NOTE: If you choose not to run the script, the installation will
fail.
Skip is an advanced option and most likely will never be wanted.

1) yes
2) no [Default - Press Enter]
3) skip

Here is a suggestion of how the prompt could look like:

Do you want to run the script? (Yes/No/Skip): y

In other words: when asking for a yes/no question, use the shorthand, similar to other windows command line tools.

Example:

  • xcopy: Overwrite C:\path\file.txt (Yes/No/All)?

For more information: https://groups.google.com/forum/#!topic/chocolatey/UVncL7PxXRg

(Moved from chocolatey-archive/chocolatey#689)

christianrondeau added a commit to christianrondeau/choco that referenced this issue Mar 25, 2015
Allows the same behavior as prompt_for_confirmation, but in a short display. Example:

`Do you want to continue? (yes/no): `
@christianrondeau
Copy link
Contributor Author

Hi,

This has been almost fully implemented, but a single detail. See: https://github.com/christianrondeau/choco/blob/22af53bac95cd701cfcc81c7a2a6ef39ceb4cfbb/src/chocolatey/infrastructure/commandline/InteractivePrompt.cs#L58 (Line 58 and 60)

There is a Log().Info(), and then a Console.ReadLine. That results in two lines. I don't see anywhere in the stack trace a line break, it seems to be within log4net that this happens... so in order to achieve what I'm trying to do here, the only way I see I can do it is by:

  1. Either I bypass log4net, and output the prompt directly to the console, and/or;
  2. I then output both the prompt AND the answer in log4net; to do this, I'll have to be able to disable console output for that second line (which might be messy), and/or;
  3. We skip completely the logging of prompts, and instead we make sure to include in the line after the prompt the selection (e.g. Are you sure? (yes/no): n then Selection: no)

If you know a better way to achieve this, let me know. For more details, here is my branch: https://github.com/christianrondeau/choco/tree/181-short-confirm-prompt

@christianrondeau
Copy link
Contributor Author

Well it looks like it's impossible with log4net.

I will then do the direct to console approach, and output the selection after, i.e. (simplified):

Console.Write("prompt: ");
String result = Console.ReadLine();
Log().Info("You have selected " + result");

This means that either 1. We don't see the prompt message in the log, or b. We see it twice in the console.

Unless we create a "prompt" logger, which would behave like the normal logger, without the console appender. Is this worth the additional complexity?

@ferventcoder
Copy link
Member

Unless we create a "prompt" logger, which would behave like the normal logger, without the console appender. Is this worth the additional complexity?

maybe...

@christianrondeau
Copy link
Contributor Author

@ferventcoder: Implemented in #204, I personally think it makes sense; most of chocolatey is just output, but this specific line preceding the readline is part of the prompting. The PR will not print in the log file, just the console; then, when we have the input, we print to the log file, but not the console. It looks good on both sides.

christianrondeau added a commit to christianrondeau/choco that referenced this issue Mar 30, 2015
christianrondeau added a commit to christianrondeau/choco that referenced this issue Mar 30, 2015
They initially came from Microsoft .Net Framework, which casts a doubt on whether it can be contained in the source code. Removing it will avoid any uncertainty.
@ferventcoder ferventcoder modified the milestone: 0.9.10 May 11, 2015
@StefanScherer
Copy link

@ferventcoder I would also love to see a prompt where I can enter y or n instead of entering numbers. This fits much better with the -y command line option.

And then chocolatey is more apt-get like.

👍 for this.

@ferventcoder
Copy link
Member

@StefanScherer you can enter the value yes no right now.

@ferventcoder
Copy link
Member

This allows using the first value. :)

@StefanScherer
Copy link

@ferventcoder I see. So 1 and yes works already, but not y:

PS C:\Users\vagrant> choco install adobereader
Chocolatey v0.9.9.5
Installing the following packages:
adobereader
By installing you accept licenses for the packages.

adobereader v11.0.10
The package adobereader wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Do you want to run the script?
 1) yes
 2) no
 3) print
y
Your choice of 'y' is not a valid selection.
You must select an answer
Do you want to run the script?
 1) yes
 2) no
 3) print
yes
 Switching to German version
 Downloading adobereader 32 bit
...

@ferventcoder
Copy link
Member

Right, the y is what this is about

@christianrondeau
Copy link
Contributor Author

By the way @ferventcoder if you need anything else from me, just let me know (I know you're swamped with the moderation load)

@ferventcoder
Copy link
Member

No worries, will get this guy in hopefully sometime this month.

@ferventcoder ferventcoder modified the milestones: 0.9.10, 0.9.10.x May 20, 2015
@christianrondeau
Copy link
Contributor Author

Rebased and merged with #184 (since they are almost the same set of changes)

@ferventcoder ferventcoder modified the milestones: 0.9.10, 0.9.10.x Mar 29, 2016
@ferventcoder ferventcoder self-assigned this Mar 29, 2016
ferventcoder pushed a commit that referenced this issue Mar 29, 2016
Right now, when asking a multiple choice question such as which version to
uninstall, there is no indication that a user input is expected. Add an input
indicator ">" to make this clearer.

Certain questions are spread out across multiple lines when they could
be on just one line as a short prompt that include the choices in parentheses.
For example, instead of

"Do you want to run the script?

1) yes
2) no
3) skip
>
"

it could simply be "Do you want to run the script? (Yes/No/Print): yes".

If the prompt allows for short answers, then provide hints that the answer
can be a single keystroke. For example
"Do you want to run the script? ([Y]es/[N]o/[P]rint): y"

In a short prompt, if there is a default answer, surround it with braces
as well. For example
"Do you want to run the script? ([[Y]es]/[N]o/[P]rint): _"
ferventcoder added a commit that referenced this issue Mar 29, 2016
* pr204:
  (GH-181)(GH-184) Short prompt/Prompt character
ferventcoder added a commit that referenced this issue Mar 29, 2016
* stable:
  (GH-460) Amended Template
  (GH-623) Extract Nuspec on Install
  (GH-674)(GH-672) Color Overrides / Fix Write-Host
  (GH-181) log selection to log file only
  (GH-181)(GH-184) Short prompt/Prompt character
  (GH-675) Template include LICENSE/VERIFICATION
  (GH-258) Rename zip to detector.zip
  (GH-572) Fix: The handle is invalid - Output Redirection
  (maint) comments
  (GH-667) Provide How To Add Profile Manually
  (GH-667) PowerShell Custom Host - Set $Profile
  (GH-666) pass Write-ChocolateyError message param
  (GH-673) Ensure Get-BinRoot Warning is Shown
  (GH-666) setup logs colored write-host w/fallback
@imranhwebdev
Copy link

Problem Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): My Problem Sloved Just y

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

5 participants