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

feat: add toggle on and off aliases to update flag #82

Conversation

lwonsower
Copy link
Contributor

@lwonsower lwonsower commented Mar 27, 2024

Based on Danny's suggestion, I went with creating a second command to create the toggle-on and toggle-off aliases

@lwonsower lwonsower requested a review from dbolson March 27, 2024 21:32
Copy link

This pull request has been linked to Shortcut Story #235707: create aliases to toggle a flag on and off.

@@ -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")
Copy link
Contributor Author

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.

cmd/flags/update.go Outdated Show resolved Hide resolved
cmd/flags/update.go Outdated Show resolved Hide resolved
@lwonsower lwonsower changed the title [235707]Add toggle on and off aliases to update flag feat: add toggle on and off aliases to update flag Mar 28, 2024
@lwonsower lwonsower force-pushed the lucywonsower/sc-235707/create-aliases-to-toggle-a-flag-on-and-off branch from 9cac621 to 0e59ec8 Compare March 29, 2024 21:34
@lwonsower lwonsower marked this pull request as ready for review March 29, 2024 21:37
@lwonsower lwonsower requested review from dbolson and sunnyguduru April 1, 2024 20:47
@@ -22,8 +22,14 @@ func NewFlagsCmd(client flags.Client) (*cobra.Command, error) {
return nil, err
}

toggleUpdateCmd, err := NewToggleUpdateCmd(client)
Copy link
Contributor

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.

@@ -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)

Copy link
Contributor

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?


var err error

cmd.Flags().String("envKey", "", "Environment key")
Copy link
Contributor

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.

return nil, err
}

cmd.Flags().String("key", "", "Flag key")
Copy link
Contributor

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))
Copy link
Contributor

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.

@lwonsower lwonsower requested a review from dbolson April 2, 2024 17:53
@lwonsower lwonsower merged commit 7b6c6f1 into main Apr 2, 2024
2 checks passed
@lwonsower lwonsower deleted the lucywonsower/sc-235707/create-aliases-to-toggle-a-flag-on-and-off branch April 2, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants