-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat: Add reusable interactive prompts and configure
command (issue #19528)
#19637
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
feat: Add reusable interactive prompts and configure
command (issue #19528)
#19637
Conversation
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
…eSettingsManager()` and `commandContext.CreateSettingsManager()` exportable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19637 +/- ##
==========================================
+ Coverage 55.07% 55.18% +0.10%
==========================================
Files 322 324 +2
Lines 54927 55078 +151
==========================================
+ Hits 30253 30393 +140
+ Misses 22068 22060 -8
- Partials 2606 2625 +19 ☔ View full report in Codecov by Sentry. |
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Hi @david-wu-octopus , can you please link the issue this PR is associated with? |
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
cmd/argocd/commands/utils/prompt.go
Outdated
enabled bool | ||
} | ||
|
||
func NewPrompt(clientOpts *apiclient.ClientOptions) (*Prompt, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to pass in clientOpts *apiclient.ClientOptions
here to reduce duplicated set up code and to make clear to other contributors that the boolean value for the prompts-enabled setting is supposed to come from local config
If we instead passed through a bool
value as the argument, it may not be clear to other developers where this value comes from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thats make sense, but i would just apply config path instead whole structure. Because here a lot of redundant fields in clients options that not relevant for prompts
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
configuration
command (issue #19528)
Done, thank you! |
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
cmd/argocd/commands/utils/prompt.go
Outdated
enabled bool | ||
} | ||
|
||
func NewPrompt(clientOpts *apiclient.ClientOptions) (*Prompt, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thats make sense, but i would just apply config path instead whole structure. Because here a lot of redundant fields in clients options that not relevant for prompts
cmd/argocd/commands/configuration.go
Outdated
fmt.Printf("prompts-enabled: %v", strconv.FormatBool(localCfg.PromptsEnabled)) | ||
}, | ||
} | ||
command.Flags().BoolVar(&promptsEnabled, "prompts-enabled", false, "Enable (or disable) optional interactive prompts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets change it to pointer and prompts, so we can verify existance of this flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the package pflag (https://github.com/spf13/pflag) doesn't actually support pointers for boolean flags
The alternative approach I've identified is for the default --prompts-enabled
and --force-prompts-enabled
flag values to be read from local configuration
cmd/argocd/commands/utils/prompt.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add override param on clientOpts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a global CLI flag --force-prompts-enabled
that will override the value in local config if it's set
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
…or `--prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
…led` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
…ntOptions` arg Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, amazing work
…rgoproj#19528) (argoproj#19637) * Add `Prompt`, with `prompts.enabled` setting in `argocd-cm` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `SettingsOpts`, `SettingsOpts.ArgocdCMPath`, `SettingsOpts.CreateSettingsManager()` and `commandContext.CreateSettingsManager()` exportable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Refactor `NewPrompt()` and move into new package `utils` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update `NewPrompt()` to use local config Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `NewConfigurationCommand()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Move `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove `prompt_test.go` for now Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add back and update `prompt_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add `configuration_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting issues Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting issues Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Reverse early-termination logic in `Confirm()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `ArgocdCMPath` to `argocdCMPath` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `SettingsOpts` to `settingsOpts` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `CreateSettingsManager()` to `createSettingsManager()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Rename `configuration` to `configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Further rename `configuration` to `configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove redundant Argo CD ConfigMap logic Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix terminal output spacing Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `argocd configure` use local config value as the default value for `--prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add global CLI flag `--force-prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update existing `prompt_test.go` test cases Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add test case for `(p *Prompt).Confirm()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add test cases for `GetBoolFlagWithFallback()` to `env_test.go` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Format imports Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Further format imports and remove unused variable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Again format imports Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add fallback to `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix bug in `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix missing import Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add auto-generated docs for `argocd configure` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add auto-generated docs for new global CLI flag `--force-prompts-enabled` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Update `NewPrompt()` to receive a `bool` rather than `*apiclient.ClientOptions` arg Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Remove arg `fallback` from `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add arg `useCLIOpts bool` to `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Make `config.LoadFlags()` exportable Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Add tests for `GetPromptsEnabled()` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Fix linting errors in tests Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> * Run `make codegen-local` Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> --------- Signed-off-by: David Wu <155603967+david-wu-octopus@users.noreply.github.com> Signed-off-by: Adrian Aneci <aneci@adobe.com>
Description
Closes #19528
This PR implements reusable functionality for interactive prompts:
prompts-enabled
flag in local configuration.argocd configure
with flag--prompts-enabled
which can be used to toggle theprompts-enabled
flag in local configuration--force-prompts-enabled
which will override the local configuration value if specifiedUsage and examples:
How to add interactive prompts to a command:
*apiclient.ClientOptions
NewPrompt(clientOpts *apiclient.ClientOptions) (*Prompt, error)
and then call(p *Prompt) Confirm(message string) bool
in the command's logicExample:
argocd admin export
commandadmin.go
:backup.go
:CLI examples
By default, optional prompts are disabled:
We can force prompts to be enabled for the current command only using a global flag
--prompts-enabled
:A new local configuration field,
prompts-enabled
, can be set to enable optional prompts for all commands as the default. To set this field, we can use a new commandargocd configuration --prompts-enabled
(where--prompts-enabled=false
will turn off optional interactive prompts):argocd configure --prompts-enabled Successfully updated the following configuration settings: prompts-enabled: true
The field will be added to the local configuration file if it isn't there already
The global flag
--force-prompts-enabled
overrides the local configuration value:Checklist: