Skip to content

Commit d01b3cf

Browse files
committed
Rename command to function
1 parent cc88401 commit d01b3cf

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

cmd/internal/completion/completion.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ func (c Completion) FindWorkspaces(toComplete string) ([]string, error) {
2929
return ws, nil
3030
}
3131

32-
func (c Completion) FindCommands(workspace string, toComplete string) ([]string, error) {
32+
func (c Completion) FindFunctions(workspace string, toComplete string) ([]string, error) {
3333
w, err := c.workspaceManager.Get(workspace)
3434
if err != nil {
3535
return []string{}, err
3636
}
37-
cs := []string{}
38-
for _, c := range w.Commands {
39-
if strings.HasPrefix(c.Command, toComplete) {
40-
s := c.Command
41-
if c.Description != "" {
42-
s = fmt.Sprintf("%s\t%s", c.Command, c.Description)
37+
fs := []string{}
38+
for _, f := range w.Functions {
39+
if strings.HasPrefix(f.Function, toComplete) {
40+
s := f.Function
41+
if f.Description != "" {
42+
s = fmt.Sprintf("%s\t%s", f.Function, f.Description)
4343
}
44-
cs = append(cs, s)
44+
fs = append(fs, s)
4545
}
4646
}
47-
return cs, nil
47+
return fs, nil
4848
}
4949

5050
func (c Completion) FindEnvs(workspace string, toComplete string) ([]string, error) {

cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var runCmd = &cobra.Command{
2626
}
2727
return workspaces, cobra.ShellCompDirectiveNoFileComp
2828
case 1:
29-
commands, err := c.FindCommands(args[0], toComplete)
29+
commands, err := c.FindFunctions(args[0], toComplete)
3030
if err != nil {
3131
return []string{}, cobra.ShellCompDirectiveNoFileComp
3232
}

cmd/show.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ var showCmd = &cobra.Command{
4242
}
4343
functionRowTableSize := []int{10, 12}
4444
fs := [][]string{}
45-
for _, c := range wo.Commands {
45+
for _, c := range wo.Functions {
4646
if c.Description == "" {
4747
c.Description = "-"
4848
}
49-
fs = append(fs, []string{c.Command, c.Description})
50-
if len(c.Command)+1 > functionRowTableSize[0] {
51-
functionRowTableSize[0] = len(c.Command) + 1
49+
fs = append(fs, []string{c.Function, c.Description})
50+
if len(c.Function)+1 > functionRowTableSize[0] {
51+
functionRowTableSize[0] = len(c.Function) + 1
5252
}
5353
if len(c.Description)+1 > functionRowTableSize[1] {
5454
functionRowTableSize[1] = len(c.Description) + 1

workspace/workspace.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
const configDir = ".config/wo"
2121

2222
type Workspace struct {
23-
Name string
24-
Commands []Command
25-
Envs []string
23+
Name string
24+
Functions []Function
25+
Envs []string
2626
}
2727

28-
type Command struct {
29-
Command string
28+
type Function struct {
29+
Function string
3030
Description string
3131
}
3232

@@ -100,20 +100,20 @@ func (s WorkspaceManager) Get(name string) (Workspace, error) {
100100
if err != nil {
101101
return Workspace{}, err
102102
}
103-
commands := []Command{}
103+
commands := []Function{}
104104
for _, f := range funcs {
105-
commands = append(commands, Command{
106-
Command: f.Name,
105+
commands = append(commands, Function{
106+
Function: f.Name,
107107
Description: f.Description,
108108
})
109109
}
110-
slices.SortFunc(commands, func(a, b Command) int {
111-
return cmp.Compare(a.Command, b.Command)
110+
slices.SortFunc(commands, func(a, b Function) int {
111+
return cmp.Compare(a.Function, b.Function)
112112
})
113113
return Workspace{
114-
Name: name,
115-
Commands: commands,
116-
Envs: envs,
114+
Name: name,
115+
Functions: commands,
116+
Envs: envs,
117117
}, nil
118118
}
119119

workspace/workspace_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func TestList(t *testing.T) {
118118
assert.NoError(t, err)
119119
assert.Len(t, ws, 3)
120120
assert.Equal(t, []Workspace{
121-
{Name: "api", Commands: []Command{}, Envs: []string{"dev"}},
122-
{Name: "db", Commands: []Command{}, Envs: []string{"staging"}},
123-
{Name: "front", Commands: []Command{}, Envs: []string{"prod"}},
121+
{Name: "api", Functions: []Function{}, Envs: []string{"dev"}},
122+
{Name: "db", Functions: []Function{}, Envs: []string{"staging"}},
123+
{Name: "front", Functions: []Function{}, Envs: []string{"prod"}},
124124
}, ws)
125125
},
126126
},
@@ -176,16 +176,16 @@ test_func2() {
176176
},
177177
func(w Workspace, err error) {
178178
assert.NoError(t, err)
179-
assert.Len(t, w.Commands, 2)
179+
assert.Len(t, w.Functions, 2)
180180
assert.Equal(t, Workspace{
181181
Name: "front",
182-
Commands: []Command{
182+
Functions: []Function{
183183
{
184-
Command: "test_func1",
184+
Function: "test_func1",
185185
Description: "A function 1",
186186
},
187187
{
188-
Command: "test_func2",
188+
Function: "test_func2",
189189
Description: "A function 2",
190190
},
191191
},

0 commit comments

Comments
 (0)