-
Notifications
You must be signed in to change notification settings - Fork 2
fix(ide): add set IDE command #450
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
4 commits
Select commit
Hold shift + click to select a range
5a4d1d7
fix(ide): honor freshly selected IDE on workspace start
skevetter 317c13e
fix(ide): guard IDE-set rollback against out-of-order responses
skevetter ab6c048
feat(ide): support persisting 'none' as a workspace IDE choice
skevetter a831635
fix(ide): disable Open IDE button when IDE is none, drop unreachable …
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package ide | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/devsy-org/devsy/cmd/flags" | ||
| "github.com/devsy-org/devsy/pkg/config" | ||
| "github.com/devsy-org/devsy/pkg/ide/ideparse" | ||
| "github.com/devsy-org/devsy/pkg/log" | ||
| "github.com/devsy-org/devsy/pkg/provider" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // SetCmd holds the set cmd flags. | ||
| type SetCmd struct { | ||
| *flags.GlobalFlags | ||
|
|
||
| Options []string | ||
| } | ||
|
|
||
| // NewSetCmd creates a command that sets the IDE for an existing workspace | ||
| // without starting the workspace. | ||
| func NewSetCmd(flags *flags.GlobalFlags) *cobra.Command { | ||
| cmd := &SetCmd{ | ||
| GlobalFlags: flags, | ||
| } | ||
| setCmd := &cobra.Command{ | ||
| Use: "set [workspace] [ide]", | ||
| Short: "Set the IDE for an existing workspace without starting it", | ||
| Long: `Set the IDE for an existing workspace without starting it. | ||
|
|
||
| The change is persisted to the workspace config and will be used on the next | ||
| 'devsy up'. Available IDEs can be listed with 'devsy ide list'.`, | ||
| RunE: func(cobraCmd *cobra.Command, args []string) error { | ||
| if len(args) != 2 { | ||
| return fmt.Errorf("usage: devsy ide set <workspace> <ide>") | ||
| } | ||
| return cmd.Run(cobraCmd.Context(), args[0], args[1]) | ||
| }, | ||
| } | ||
|
|
||
| setCmd.Flags(). | ||
| StringArrayVarP(&cmd.Options, "option", "o", []string{}, "IDE option in the form KEY=VALUE") | ||
| return setCmd | ||
| } | ||
|
|
||
| // Run runs the command logic. | ||
| func (cmd *SetCmd) Run(_ context.Context, workspaceID, ideName string) error { | ||
| devsyConfig, err := config.LoadConfig(cmd.Context, cmd.Provider) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| contextName := devsyConfig.DefaultContext | ||
| if !provider.WorkspaceExists(contextName, workspaceID) { | ||
| return fmt.Errorf("workspace %q not found in context %q", workspaceID, contextName) | ||
| } | ||
|
|
||
| workspace, err := provider.LoadWorkspaceConfig(contextName, workspaceID) | ||
| if err != nil { | ||
| return fmt.Errorf("load workspace config: %w", err) | ||
| } | ||
|
|
||
| ideName = strings.ToLower(ideName) | ||
| if _, err := ideparse.GetIDEOptions(ideName); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| workspace, err = ideparse.RefreshIDEOptions(devsyConfig, workspace, ideName, cmd.Options) | ||
| if err != nil { | ||
| return fmt.Errorf("refresh ide options: %w", err) | ||
| } | ||
|
|
||
| log.Infof("set IDE for workspace %q to %q", workspace.ID, workspace.IDE.Name) | ||
| 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
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
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.
Add an explicit “clear IDE” path instead of rejecting non-IDE sentinels.
Right now this flow only accepts recognized IDE names. That blocks persisting a “no IDE” selection for existing workspaces, so stale workspace IDE config can remain active in later starts when
--ideis omitted. Please support an explicit unset value (e.g.,none) or a dedicated unset command and persist that state.🤖 Prompt for AI Agents