-
Notifications
You must be signed in to change notification settings - Fork 154
Do not load host from bundle for CLI commands when profile flag is used #2335
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
Changes from all commits
57c721e
a79504e
051d36e
f08770a
df4e032
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,6 +195,12 @@ func MustWorkspaceClient(cmd *cobra.Command, args []string) error { | |
| cfg.Profile = profile | ||
| } | ||
|
|
||
| _, isTargetFlagSet := targetFlagValue(cmd) | ||
| // If the profile flag is set but the target flag is not, we should skip loading the bundle configuration. | ||
| if !isTargetFlagSet && hasProfileFlag { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if both -p and -t are set? Should that result in an error? or is it a valid use case as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid use case, for example, you want to make a CLI call to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a valid case, should the condition be
so if -p is provided, then we always use that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we use this condition we will skip bundle configuration always, even when -t is provided. But we don't want to skip it when -t is provided |
||
| cmd.SetContext(SkipLoadBundle(cmd.Context())) | ||
shreyas-goenka marked this conversation as resolved.
Show resolved
Hide resolved
andrewnester marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| ctx := cmd.Context() | ||
| ctx = context.WithValue(ctx, &configUsed, cfg) | ||
| cmd.SetContext(ctx) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,26 +14,35 @@ import ( | |
|
|
||
| // getTarget returns the name of the target to operate in. | ||
| func getTarget(cmd *cobra.Command) (value string) { | ||
| target, isFlagSet := targetFlagValue(cmd) | ||
| if isFlagSet { | ||
| return target | ||
| } | ||
|
|
||
| // If it's not set, use the environment variable. | ||
| target, _ = env.Target(cmd.Context()) | ||
| return target | ||
| } | ||
|
|
||
| func targetFlagValue(cmd *cobra.Command) (string, bool) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the motivation for ignoring env var but taking command line option into account?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean not having the same behaviour like with flag set? |
||
| // The command line flag takes precedence. | ||
| flag := cmd.Flag("target") | ||
| if flag != nil { | ||
| value = flag.Value.String() | ||
| value := flag.Value.String() | ||
| if value != "" { | ||
| return | ||
| return value, true | ||
| } | ||
| } | ||
|
|
||
| oldFlag := cmd.Flag("environment") | ||
| if oldFlag != nil { | ||
| value = oldFlag.Value.String() | ||
| value := oldFlag.Value.String() | ||
| if value != "" { | ||
| return | ||
| return value, true | ||
| } | ||
| } | ||
|
|
||
| // If it's not set, use the environment variable. | ||
| target, _ := env.Target(cmd.Context()) | ||
| return target | ||
| return "", false | ||
| } | ||
|
|
||
| func getProfile(cmd *cobra.Command) (value string) { | ||
|
|
||
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.
nit: I'd replace "Should use profile from the flag" with 'Prefers profile passed via "-p profile_name" over the one specified by bundle host'.