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

Optional interactive #536

Closed
Zethson opened this issue Oct 30, 2018 · 9 comments
Closed

Optional interactive #536

Zethson opened this issue Oct 30, 2018 · 9 comments
Labels
theme: parser An issue or change related to the parser type: enhancement ✨
Milestone

Comments

@Zethson
Copy link

Zethson commented Oct 30, 2018

Hi,

I'm having the following issue:
I have a password CommandLine.Option, which is currently interactive -> thus it asks the user for his password.
However, I would like to skip the interactive question, if a password was already provided.

Is it possible to consume the interactive request?

@remkop
Copy link
Owner

remkop commented Oct 30, 2018

@Zethson At the moment picocli does not support this. There is a section in the manual about combining interactive use with non-interactive use.

Basically, if you need this, one idea is to have separate options, like --password:hidden for the interactive option, and --password:clear that accepts the password in cleartext as an option parameter on the command line. For batch scripts it may be more secure to ask the user to specify a file or environment variable that holds the password.

@Zethson
Copy link
Author

Zethson commented Oct 30, 2018

I see, thanks!
I still would like to kindly request this feature.

It's more or less the only thing that I miss from Click .

@remkop
Copy link
Owner

remkop commented Oct 30, 2018

Understood. Not sure when I'll get to it.
I'm a bit worried about introducing ambiguity, for example:

class App {
    @Option(names = "--password", interactive = true)
    String password;

    @Parameters
    String[] otherParams;
}

Now, if the end user specifies some input:

<command> --password aaa bbb ccc

Currently picocli will interactively ask for a password and put aaa, bbb and ccc in the otherParameters array.

This will change after this feature request is implemented: for the same input, the aaa parameter will now be interpreted as a password parameter value. Not sure yet how to deal with this...

@Zethson
Copy link
Author

Zethson commented Oct 30, 2018

What Click does is that every parameter that was not passed and labeled as interactive is prompted. Everything that was passed is not going to be prompted.
--password aaa bbb ccc
is going to set aaa as value for password

aaa bbb ccc
will open the interactive prompt and ask for the password, since no value for password was passed.

@remkop
Copy link
Owner

remkop commented Oct 30, 2018

I guess I will either have to live with potentially breaking existing applications, or introduce some extra flag that needs to be set for picocli to accept values following --password as the password value.

@Zethson
Copy link
Author

Zethson commented Oct 30, 2018

I'm afraid yes.

I prefer the potentially breaking change, but this is of course up to you.

Thanks!

@remkop remkop added this to the 4.0 milestone Dec 13, 2018
@remkop
Copy link
Owner

remkop commented Dec 21, 2018

JCommander actually implemented this feature request:

But that caused an issue in certain use cases (application did not want to allow users to specify the password in plain text as an option parameter):

One possible solution for this last use case is to use arity to control whether option parameters are allowed: by default the arity for an interactive = true argument would be 0..1, meaning end user may specify it as an option parameter, or may omit it and get prompted on the command line.

If the application author defines the option with arity = "0", picocli would not allow end users to specify it as an option parameter and always prompt for a value on the console.

@remkop remkop modified the milestones: 4.0, 3.9.6 Mar 23, 2019
remkop added a commit that referenced this issue Apr 5, 2019
…f type `char[]`

* [#657] Support type `char[]` for interactive options
* [#536] Support optionally interactive options

Closes #536
Closes #657
@remkop
Copy link
Owner

remkop commented Apr 6, 2019

@Zethson, it took a while, but this has finally been implemented. By default, interactive options now have arity = "0" (meaning they won’t consume any command line arguments but prompt the user for input instead), but if the option is defined with arity = "0..1", it may optionally consume a parameter from the command line arguments.

I’ll release 3.9.6 with this change soon.

@Zethson
Copy link
Author

Zethson commented Apr 6, 2019

Amazing. Thank you for your hard work.

@remkop remkop closed this as completed in 9094c5e Apr 6, 2019
remkop added a commit that referenced this issue Apr 6, 2019
@remkop remkop added the theme: parser An issue or change related to the parser label Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: parser An issue or change related to the parser type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

2 participants