-
Notifications
You must be signed in to change notification settings - Fork 428
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
fix(cli): --app flag can now be overridden by users #1399
Conversation
type GlobalOpts struct { | ||
appName string | ||
prompt prompter | ||
} |
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.
Curious if it's possible to keep GlobalOpts and therefore maintain DRYness across all the command Opts but just get rid of the bindAppName
logic?
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.
GlobalOpts
itself is not great because it resulted in commands getting a prompt
whether they needed it or not, and we had a bunch of commands that never used it :(
An alternative that doesn't force the re-declaration of the --app
flag in these sub-commands that I can think of is this: https://gist.github.com/efekarakus/37144a1a4b8792508c39e9927a020243
The benefit is that we don't have to remember to add the flag for all these sub-commands.
But, the downside is that I find this harder to understand as a reader than:
cmd.Flags().StringVarP(&vars.appName, appFlag, appFlagShort, tryReadingAppName(), appFlagDescription)
This makes it obvious if the --app
flag is part of the command or not.
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.
Thank for the efforts for making this happen! It's such an annoying problem. A general question: have you run e2e test to make sure if they all work as expected?
github.com/spf13/pflag v1.0.5 | ||
github.com/spf13/viper v1.7.1 |
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.
👋
Yea after 2h44mins success :) |
Resolves aws#1329 Removes GlobalOpts struct and the viper lib dependency from the CLI. Previously, if we ran "env init --app other" the overridden value "other" was ignored and only the workspace's app was used. This is an issue with viper as was found in aws#1329. Instead, with this change we get rid of Global Flags and force commands themselves to write whether they need an --app flag or not.
355633a
to
6938fb3
Compare
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.
Looks good, just a question about testing something in init.
return nil | ||
} | ||
|
||
func (o *initOpts) loadSvc() error { | ||
if initSvcOpts, ok := o.initSvcCmd.(*initSvcOpts); ok { |
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.
Is there a way to test this case?
Resolves aws#1329 Removes GlobalOpts struct and the viper lib dependency from the CLI. Previously, if we ran "env init --app other" the overridden value "other" was ignored and only the workspace's app was used. This is an issue with viper as was found in aws#1329. Instead, with this change we get rid of Global Flags and force commands themselves to write whether they need an --app flag or not. _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
Resolves #1329
Removes GlobalOpts struct and the viper lib dependency from the CLI.
Previously, if we ran "env init --app other" the overridden value
"other" was ignored and only the workspace's app was used.
This is an issue with viper as was found in #1329. Instead, with this
change we get rid of Global Flags and force commands themselves to write
whether they need an --app flag or not.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.