-
Notifications
You must be signed in to change notification settings - Fork 31
feat(config): add ignore-existing for profile create #1094
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
base: main
Are you sure you want to change the base?
Conversation
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
cc @rubenhoenle |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
|
||
| func configureFlags(cmd *cobra.Command) { | ||
| cmd.Flags().Bool(noSetFlag, false, "Do not set the profile as the active profile") | ||
| cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error it the profile exists already") |
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.
typo
| cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error it the profile exists already") | |
| cmd.Flags().Bool(ignoreExistingFlag, false, "Suppress the error if the profile exists already") |
| // CreateProfile creates a new profile. | ||
| // If emptyProfile is true, it creates an empty profile. Otherwise, copies the config from the current profile to the new profile. | ||
| // If setProfile is true, it sets the new profile as the active profile. | ||
| // If the profile already exists, it returns an error. |
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.
| // If the profile already exists, it returns an error. | |
| // If the profile already exists and ignoreExisting is false, it returns an error. |
| _, err = os.Stat(configFolderPath) | ||
| if err == nil { | ||
| if ignoreExising { | ||
| return nil |
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.
| return nil | |
| if setProfile { | |
| err = SetProfile(p, profile) | |
| if err != nil { | |
| return fmt.Errorf("set profile: %w", err) | |
| } | |
| } | |
| return nil |
Currently the value of setProfile is ignored, when this branch is taken.
When creating a profile with --ignore-existing, that already exists but isn't active at the moment, the CLI reports:
Successfully created and set active profile to "qa"
'qa' isn't activated in this case.
Description
This PR adds
--ignore-existingas a flag forstackit config profile createin order to call the create idempotent and don not get a error in case the profile already exists. That make it possible to use profiles in automation/tool.Example: I am currently integrating stackit(-cli) into the gardenctl (gardener/gardenctl-v2#669).
Checklist
make fmtmake generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)