@@ -9,7 +9,7 @@ var DefaultHelpInput = NewBoolOpt("help").
99
1010var (
1111 errMixingPosArgsAndSubcmds = "commands cannot have both positional args and subcommands"
12- errEmptyCmdName = invalidCmdNameError {}
12+ errEmptyCmdName = "empty command name"
1313 errEmptyInputID = "inputs must have non-empty, unique ids"
1414 errEmptyOptNames = "options must have either a short or long name"
1515 errOptAsPosArg = "adding an option as a positional argument"
@@ -27,27 +27,18 @@ func (c *CommandInfo) validate() {
2727 for z := i + 1 ; z < len (c .opts ); z ++ {
2828 // assert there are no duplicate input ids
2929 if c .opts [i ].id == c .opts [z ].id {
30- panic (illegalDupError {
31- cmdPath : strings .Join (c .path , " " ),
32- what : "ids" ,
33- dups : c .opts [i ].id ,
34- })
30+ panic ("command '" + strings .Join (c .path , " " ) +
31+ "' contains duplicate option ids '" + c .opts [i ].id + "'" )
3532 }
3633
3734 // assert there are no duplicate long or short option names
3835 if c .opts [i ].nameShort != "" && c .opts [i ].nameShort == c .opts [z ].nameShort {
39- panic (illegalDupError {
40- cmdPath : strings .Join (c .path , " " ),
41- what : "option short names" ,
42- dups : c .opts [i ].nameShort ,
43- })
36+ panic ("command '" + strings .Join (c .path , " " ) +
37+ "' contains duplicate option short name '" + c .opts [i ].nameShort + "'" )
4438 }
4539 if c .opts [i ].nameLong != "" && c .opts [i ].nameLong == c .opts [z ].nameLong {
46- panic (illegalDupError {
47- cmdPath : strings .Join (c .path , " " ),
48- what : "option long names" ,
49- dups : c .opts [i ].nameLong ,
50- })
40+ panic ("command '" + strings .Join (c .path , " " ) +
41+ "' contains duplicate option long name '" + c .opts [i ].nameLong + "'" )
5142 }
5243 }
5344 }
@@ -56,11 +47,8 @@ func (c *CommandInfo) validate() {
5647 for i := 0 ; i < len (c .args )- 1 ; i ++ {
5748 for z := i + 1 ; z < len (c .args ); z ++ {
5849 if c .args [i ].id == c .args [z ].id {
59- panic (illegalDupError {
60- cmdPath : strings .Join (c .path , " " ),
61- what : "ids" ,
62- dups : c .args [i ].id ,
63- })
50+ panic ("command '" + strings .Join (c .path , " " ) +
51+ "' contains duplicate argument ids '" + c .args [i ].id + "'" )
6452 }
6553 }
6654 }
@@ -69,11 +57,8 @@ func (c *CommandInfo) validate() {
6957 for i := 0 ; i < len (c .subcmds )- 1 ; i ++ {
7058 for z := i + 1 ; z < len (c .subcmds ); z ++ {
7159 if c .subcmds [i ].name == c .subcmds [z ].name {
72- panic (illegalDupError {
73- cmdPath : strings .Join (c .path , " " ),
74- what : "subcommand names" ,
75- dups : c .subcmds [i ].name ,
76- })
60+ panic ("command '" + strings .Join (c .path , " " ) +
61+ "' contains duplicate subcommand name '" + c .subcmds [i ].name + "'" )
7762 }
7863 }
7964 }
@@ -83,28 +68,6 @@ func (c *CommandInfo) validate() {
8368 }
8469}
8570
86- type illegalDupError struct {
87- cmdPath string
88- what string // input ids, option short names, option long names, subcmd names
89- dups string
90- }
91-
92- func (e illegalDupError ) String () string {
93- return "command '" + e .cmdPath + "' contains options with duplicate " + e .what + " '" + e .dups + "'"
94- }
95-
96- type invalidCmdNameError struct {
97- name string
98- reason string
99- }
100-
101- func (e invalidCmdNameError ) String () string {
102- if e .name == "" {
103- return "empty command name"
104- }
105- return "invalid command name '" + e .name + "': " + e .reason
106- }
107-
10871func NewCmd (name string ) CommandInfo {
10972 // assert command name isn't empty and doesn't contain any whitespace
11073 if name == "" {
@@ -113,10 +76,7 @@ func NewCmd(name string) CommandInfo {
11376 for i := range name {
11477 switch name [i ] {
11578 case ' ' , '\t' , '\n' , '\r' :
116- panic (invalidCmdNameError {
117- name : name ,
118- reason : "cannot contain whitespace" ,
119- })
79+ panic ("invalid command name '" + name + "': cannot contain whitespace" )
12080 }
12181 }
12282
0 commit comments