How to configure a prompt with a default that comes from another option?
See original GitHub issueI’m trying to setup a command that takes multiple sets of credentials (for different things) as options. All of them can be prompted for, but I would like the first username to be shown and used as default value for other username prompts.
class MyCommand : CliktCommand() {
val githubUser by option("--github-user").prompt("Your GitHub username")
val bintrayUser by option("--bintray-user").prompt("Your Bintray username", default = githubUser)
}
This obviously doesn’t work because githubUser
doesn’t have a value at this time.
Is there a way to provide a default with a lambda?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to set a default app to prompt for a choice?
I would like to set the default for a file type to prompt me to choose which app I want to use. (I...
Read more >Set default prompt set value dynamically based on value from ...
I would like to find a way to dynamically set the default value of one field in a prompt set based on the...
Read more >Changing the default behavior of the 'Search and Select' Prompt
Option (1) is the default choice. There is no prompt control property available to set which option is applied by default.
Read more >Creating a Click.Option with prompt that shows only if default ...
This can be done by over riding the click.Option.get_default() and the click.Option.prompt_for_value() methods like: Custom Class:.
Read more >How to set Default to in Dashboard Prompt from presentation ...
Leave the second dashboard page's prompt "default" or if you want a value, set it to "Male" or "Female." When a selection is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Jake is right, you can use
defaultLazy
here.option().prompt()
just callsTermUi.prompt
under the hood, so you can do the same:There’s a caveat that default values (including
prompt()
) are evaluated in the order they’re defined, so make sure you’re only referencing properties defined earlier in the command. If you don’t want to rely on the definition order, you can callTermUi.prompt
manually fromrun
.That makes sense. I was somehow too focused on the
prompt()
shorthand. Thanks!