-
Notifications
You must be signed in to change notification settings - Fork 3
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 toggle on and off aliases to update flag #82
feat: add toggle on and off aliases to update flag #82
Conversation
This pull request has been linked to Shortcut Story #235707: create aliases to toggle a flag on and off. |
cmd/flags/update.go
Outdated
@@ -29,7 +31,17 @@ func NewUpdateCmd(client flags.Client) (*cobra.Command, error) { | |||
"", | |||
"Input data in JSON", | |||
) | |||
err := cmd.MarkFlagRequired("data") | |||
|
|||
cmd.Flags().String("envKey", "", "Environment key") |
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.
We need to require an envKey when using the aliases, but not otherwise. Same for the data flag below, we do not require it when using the aliases. I can't figure out a way to conditionally require flags here.
9cac621
to
0e59ec8
Compare
cmd/flags/flags.go
Outdated
@@ -22,8 +22,14 @@ func NewFlagsCmd(client flags.Client) (*cobra.Command, error) { | |||
return nil, err | |||
} | |||
|
|||
toggleUpdateCmd, err := NewToggleUpdateCmd(client) |
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.
It looks like only "toggle-on" shows up when running help, so it's not obvious that there's a "toggle-off" command. It may be worth splitting this up into two separate commands so we get the automatic framework stuff to work as expected.
cmd/flags/update.go
Outdated
@@ -25,6 +25,7 @@ func NewUpdateCmd(client flags.Client) (*cobra.Command, error) { | |||
|
|||
cmd.Flags().StringP(cliflags.DataFlag, "d", "", "Input data in JSON") | |||
err := cmd.MarkFlagRequired(cliflags.DataFlag) | |||
|
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.
Could you remove this newline to keep the error assignment and check next to each other so it's easier to see they're related?
cmd/flags/update.go
Outdated
|
||
var err error | ||
|
||
cmd.Flags().String("envKey", "", "Environment key") |
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.
You can use cliflags.EnvironmentFlag
if you pull the most recent main.
cmd/flags/update.go
Outdated
return nil, err | ||
} | ||
|
||
cmd.Flags().String("key", "", "Flag key") |
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.
Can you make this cliflags.FlagFlag
(we'll probably rename these to remove the stutter)?
|
||
return cmd, nil | ||
} | ||
|
||
func runUpdate(client flags.Client) func(*cobra.Command, []string) error { | ||
return func(cmd *cobra.Command, args []string) error { | ||
// rebind flags used in other subcommands | ||
_ = viper.BindPFlag(cliflags.DataFlag, cmd.Flags().Lookup(cliflags.DataFlag)) | ||
_ = viper.BindPFlag(cliflags.ProjectFlag, cmd.Flags().Lookup(cliflags.ProjectFlag)) |
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.
You may need to rebind the flag
key as well.
Based on Danny's suggestion, I went with creating a second command to create the
toggle-on
andtoggle-off
aliases