Skip to content

Commit 96a798c

Browse files
authored
fix(cdsctl): bad sort of arg when mixed with ctx arg, remove weight (#5211)
1 parent 5ce1251 commit 96a798c

File tree

6 files changed

+9
-50
lines changed

6 files changed

+9
-50
lines changed

cli/cdsctl/application_variable.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ var applicationVariableCreateCmd = cli.Command{
3030
{Name: _ApplicationName},
3131
},
3232
Args: []cli.Arg{
33-
{Name: "variable-name", Weight: 1},
34-
{Name: "variable-type", Weight: 2},
35-
{Name: "variable-value", Weight: 3},
33+
{Name: "variable-name"},
34+
{Name: "variable-type"},
35+
{Name: "variable-value"},
3636
},
3737
}
3838

@@ -102,10 +102,10 @@ var applicationVariableUpdateCmd = cli.Command{
102102
{Name: _ApplicationName},
103103
},
104104
Args: []cli.Arg{
105-
{Name: "variable-oldname", Weight: 1},
106-
{Name: "variable-name", Weight: 2},
107-
{Name: "variable-type", Weight: 3},
108-
{Name: "variable-value", Weight: 4},
105+
{Name: "variable-oldname"},
106+
{Name: "variable-name"},
107+
{Name: "variable-type"},
108+
{Name: "variable-value"},
109109
},
110110
}
111111

cli/cdsctl/workflow_log.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ var workflowLogListCmd = cli.Command{
6565
match, _ := regexp.MatchString(`[0-9]?`, s)
6666
return match
6767
},
68-
Weight: 1,
6968
},
7069
},
7170
}
@@ -196,7 +195,6 @@ var workflowLogDownloadCmd = cli.Command{
196195
match, _ := regexp.MatchString(`[0-9]?`, s)
197196
return match
198197
},
199-
Weight: 1,
200198
},
201199
},
202200
Flags: []cli.Flag{

cli/cdsctl/workflow_run_history.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ var workflowHistoryCmd = cli.Command{
2020
match, _ := regexp.MatchString(`[0-9]?`, s)
2121
return match
2222
},
23-
Weight: 1,
2423
},
2524
{
2625
Name: "limit",
2726
IsValid: func(s string) bool {
2827
match, _ := regexp.MatchString(`[0-9]?`, s)
2928
return match
3029
},
31-
Weight: 2,
3230
},
3331
},
3432
}

cli/cdsctl/workflow_stop.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ cdsctl workflow stop MYPROJECT myworkflow 5 compile # To stop a workflow node ru
2020
},
2121
OptionalArgs: []cli.Arg{
2222
{
23-
Name: "run-number",
24-
Weight: 1,
23+
Name: "run-number",
2524
},
2625
{
27-
Name: "node-name",
28-
Weight: 2,
26+
Name: "node-name",
2927
},
3028
},
3129
}

cli/cobra.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ func newCommand(c Command, run interface{}, subCommands SubCommands, mods ...Com
8787
cmd.SetOutput(os.Stdout)
8888
cmd.Use = c.Name
8989

90-
sort.Sort(orderArgs(c.Args...))
91-
sort.Sort(orderArgs(c.OptionalArgs...))
92-
9390
if len(c.Ctx) > 0 {
9491
cmd.Use = cmd.Use + " ["
9592
}
@@ -138,7 +135,6 @@ func newCommand(c Command, run interface{}, subCommands SubCommands, mods ...Com
138135

139136
definedArgs := append(c.Ctx, c.Args...)
140137
definedArgs = append(definedArgs, c.OptionalArgs...)
141-
sort.Sort(orderArgs(definedArgs...))
142138
definedArgs = append(definedArgs, c.VariadicArgs)
143139

144140
cmd.Short = c.Short

cli/types.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"fmt"
55
"reflect"
6-
"sort"
76
"strconv"
87
"strings"
98

@@ -83,39 +82,9 @@ func (v *Values) GetStringArray(s string) []string {
8382
type Arg struct {
8483
Name string
8584
IsValid func(string) bool
86-
Weight int
8785
AllowEmpty bool
8886
}
8987

90-
func orderArgs(a ...Arg) args {
91-
for i := range a {
92-
if a[i].Weight == 0 {
93-
a[i].Weight = i
94-
}
95-
}
96-
res := args(a)
97-
sort.Sort(res)
98-
return res
99-
}
100-
101-
type args []Arg
102-
103-
// Len is the number of elements in the collection.
104-
func (s args) Len() int {
105-
return len(s)
106-
}
107-
108-
// Less reports whether the element with
109-
// index i should sort before the element with index j.
110-
func (s args) Less(i, j int) bool {
111-
return s[i].Weight < s[j].Weight
112-
}
113-
114-
// Swap swaps the elements with indexes i and j.
115-
func (s args) Swap(i, j int) {
116-
s[i], s[j] = s[j], s[i]
117-
}
118-
11988
// Command represents the way to instantiate a cobra.Command
12089
type Command struct {
12190
Name string

0 commit comments

Comments
 (0)