commands: Do command collision check in GetOptions
Matt Bell committed
Oct 21, 2014 at 17:39 UTC
6ff98df9c10a16fff9205f3686f0b576ad0d70d8
1 file changed
+6
-2
commands/command.go
+6
-2
@@ -111,13 +111,13 @@ func (c *Command) Get(path []string) (*Command, error) {
111
// GetOptions gets the options in the given path of commands
112
func (c *Command) GetOptions(path []string) (map[string]Option, error) {
113
options := make([]Option, len(c.Options))
114
- copy(options, c.Options)
115
- options = append(options, globalOptions...)
114
115
cmds, err := c.Resolve(path)
116
if err != nil {
117
return nil, err
118
}
119
+ cmds = append(cmds, globalCommand)
120
+
121
for _, cmd := range cmds {
122
options = append(options, cmd.Options...)
123
}
@@ -125,6 +125,10 @@ func (c *Command) GetOptions(path []string) (map[string]Option, error) {
125
optionsMap := make(map[string]Option)
126
for _, opt := range options {
127
for _, name := range opt.Names {
128
+ if _, found := optionsMap[name]; found {
129
+ return nil, fmt.Errorf("Option name '%s' used multiple times", name)
130
+ }
131
+
132
optionsMap[name] = opt
133
}
134
}