Skip to content

Commit

Permalink
Merge edit and edit-env
Browse files Browse the repository at this point in the history
  • Loading branch information
antham committed Apr 28, 2024
1 parent c87ab0b commit 5ebb71b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
18 changes: 15 additions & 3 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

// editCmd represents the edit command
var editCmd = &cobra.Command{
Use: "edit workspace",
Use: "edit workspace [environment]",
Short: "Edit a workspace",
Args: cobra.ExactArgs(1),
Args: cobra.RangeArgs(1, 2),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
w, err := workspace.NewWorkspaceManager()
if err != nil {
Expand All @@ -24,6 +24,12 @@ var editCmd = &cobra.Command{
return []string{}, cobra.ShellCompDirectiveNoFileComp
}
return workspaces, cobra.ShellCompDirectiveNoFileComp
case 1:
envs, err := c.FindEnvs(args[0], toComplete)
if err != nil {
return []string{}, cobra.ShellCompDirectiveNoFileComp
}
return envs, cobra.ShellCompDirectiveNoFileComp
}
return []string{}, cobra.ShellCompDirectiveNoFileComp
},
Expand All @@ -32,7 +38,13 @@ var editCmd = &cobra.Command{
if err != nil {
return err
}
return w.Edit(args[0])
switch len(args) {
case 1:
w.Edit(args[0])

Check failure on line 43 in cmd/edit.go

View workflow job for this annotation

GitHub Actions / call-workflow / lint

Error return value of `w.Edit` is not checked (errcheck)
case 2:
w.EditEnv(args[0], args[1])

Check failure on line 45 in cmd/edit.go

View workflow job for this annotation

GitHub Actions / call-workflow / lint

Error return value of `w.EditEnv` is not checked (errcheck)
}
return nil
},
}

Expand Down
28 changes: 0 additions & 28 deletions cmd/editEnv.go

This file was deleted.

14 changes: 14 additions & 0 deletions cmd/internal/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ func (c Completion) FindCommands(workspace string, toComplete string) ([]string,
}
return cs, nil
}

func (c Completion) FindEnvs(workspace string, toComplete string) ([]string, error) {
w, err := c.workspaceManager.Get(workspace)
if err != nil {
return []string{}, err
}
envs := []string{}
for _, env := range w.Envs {
if strings.HasPrefix(env, toComplete) {
envs = append(envs, env)
}
}
return envs, nil
}

0 comments on commit 5ebb71b

Please sign in to comment.