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

fix(cli): --app flag can now be overridden by users #1399

Merged
merged 2 commits into from
Sep 21, 2020

Conversation

efekarakus
Copy link
Contributor

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.

@efekarakus efekarakus requested a review from a team as a code owner September 18, 2020 21:11
@efekarakus efekarakus removed the request for review from kohidave September 18, 2020 21:13
Comment on lines -22 to -25
type GlobalOpts struct {
appName string
prompt prompter
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@iamhopaul123 iamhopaul123 left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋

@efekarakus
Copy link
Contributor Author

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?

Yea after 2h44mins success :)

@efekarakus efekarakus added do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. and removed do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. labels Sep 21, 2020
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.
Copy link
Contributor

@bvtujo bvtujo left a 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 {
Copy link
Contributor

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?

@mergify mergify bot merged commit d7ce60e into aws:mainline Sep 21, 2020
@efekarakus efekarakus deleted the fix/global-app-flag branch September 22, 2020 02:17
thrau pushed a commit to localstack/copilot-cli-local that referenced this pull request Dec 9, 2022
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._
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.

--app doesn't work for env commands
4 participants