-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(cli)!: harmonize provider verbs and add rm/mv aliases #469
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ebb3f7
refactor(cli)!: rename 'provider configure' to 'provider init'
skevetter db27f5b
refactor(cli)!: rename 'provider update' to 'provider set-source'
skevetter 484a92e
refactor(cli)!: update in-tree references to renamed provider verbs
skevetter aa19b6c
feat(cli): add 'rm' alias to delete commands across groups
skevetter 9a8f354
feat(cli): add 'mv' alias to rename commands
skevetter bc9a4d9
test(e2e): use renamed 'provider init' and 'provider set-source' verbs
skevetter 46d732e
feat(desktop)!: use renamed 'provider init' and 'provider set-source'…
skevetter 1572eef
docs!: update provider command references to renamed verbs
skevetter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package provider | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/devsy-org/devsy/cmd/flags" | ||
| "github.com/devsy-org/devsy/pkg/config" | ||
| "github.com/devsy-org/devsy/pkg/log" | ||
| "github.com/devsy-org/devsy/pkg/workspace" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // SetSourceCmd holds the cmd flags. | ||
| type SetSourceCmd struct { | ||
| *flags.GlobalFlags | ||
|
|
||
| Use bool | ||
| Version string | ||
| Options []string | ||
| } | ||
|
|
||
| // NewSetSourceCmd creates a new command. | ||
| func NewSetSourceCmd(flags *flags.GlobalFlags) *cobra.Command { | ||
| cmd := &SetSourceCmd{ | ||
| GlobalFlags: flags, | ||
| } | ||
| setSourceCmd := &cobra.Command{ | ||
| Use: "set-source [name] [name, GitHub link, URL or path]", | ||
| Short: "Set or change a provider's source (replaces the registered name, repo, URL, or path)", | ||
| RunE: func(cobraCmd *cobra.Command, args []string) error { | ||
| ctx := cobraCmd.Context() | ||
| devsyConfig, err := config.LoadConfig(cmd.Context, cmd.Provider) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return cmd.Run(ctx, devsyConfig, args) | ||
| }, | ||
| } | ||
|
|
||
| setSourceCmd.Flags(). | ||
| BoolVar(&cmd.Use, "use", true, "If enabled will automatically activate the provider") | ||
| setSourceCmd.Flags(). | ||
| StringVar(&cmd.Version, "version", "", "Pin the provider to a specific version tag") | ||
| setSourceCmd.Flags(). | ||
| StringArrayVarP(&cmd.Options, "option", "o", []string{}, "Provider option in the form KEY=VALUE") | ||
| return setSourceCmd | ||
| } | ||
|
|
||
| func (cmd *SetSourceCmd) Run(ctx context.Context, devsyConfig *config.Config, args []string) error { | ||
| if cmd.Version != "" { | ||
| return cmd.runPinVersion(devsyConfig, args) | ||
| } | ||
|
|
||
| if len(args) != 1 && len(args) != 2 { | ||
| return fmt.Errorf("specify either a local file, URL or Git repository. " + | ||
| "E.g. devsy provider set-source my-provider " + config.ProviderPrefix + "gcloud") | ||
| } | ||
|
|
||
| providerSource := "" | ||
| if len(args) == 2 { | ||
| providerSource = args[1] | ||
| } | ||
|
|
||
| providerConfig, err := workspace.UpdateProvider(devsyConfig, args[0], providerSource) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| log.Infof("updated provider: providerName=%s", providerConfig.Name) | ||
| if !cmd.Use { | ||
| log.Infof("To initialize the provider, run: devsy provider init %s", providerConfig.Name) | ||
| return nil | ||
| } | ||
|
|
||
| if err := ConfigureProvider(ctx, ProviderOptionsConfig{ | ||
| Provider: providerConfig, | ||
| Context: devsyConfig.DefaultContext, | ||
| UserOptions: cmd.Options, | ||
| }); err != nil { | ||
| log.Errorf( | ||
| "Error initializing provider, retry with 'devsy provider init %s --reconfigure'", | ||
| providerConfig.Name, | ||
| ) | ||
| return fmt.Errorf("configure provider: %w", err) | ||
| } | ||
|
|
||
| return writeDefaultProvider(cmd.Context, providerConfig.Name) | ||
| } | ||
|
|
||
| func (cmd *SetSourceCmd) runPinVersion(devsyConfig *config.Config, args []string) error { | ||
| if len(args) == 0 { | ||
| return fmt.Errorf("provider name must be provided when using --version") | ||
| } | ||
| if len(args) > 1 { | ||
| return fmt.Errorf("--version and a source argument are mutually exclusive") | ||
| } | ||
| providerName := args[0] | ||
| if err := workspace.SetProviderVersion(devsyConfig, providerName, cmd.Version); err != nil { | ||
| return err | ||
| } | ||
| log.Infof("pinned provider %s to version %s", providerName, cmd.Version) | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 107
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 7111
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 10191
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 5179
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 9187
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 510
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 7492
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 2110
🏁 Script executed:
Repository: devsy-org/devsy
Length of output: 28043
set-sourceshould likely passReconfigure: trueafter swapping provider sourcecmd/provider/set_source.gocallsConfigureProviderwithoutReconfigure, soconfigure_shared.gowill merge existing user-provided option values into the new option resolution (mergeExistingOptionswhen!cfg.Reconfigure). This differs fromprovider add(setsReconfigure: true) andpro update-provider(also setsReconfigure: true). Consider settingReconfigure: true(and explicitly setting other defaults for clarity) to avoid carrying stale user-provided option values across source/schema changes.🤖 Prompt for AI Agents