File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "runtime/debug"
55 "slices"
66 "strings"
7+ "unicode"
78)
89
910var DefaultHelpInput = NewBoolOpt ("help" ).
@@ -109,25 +110,25 @@ func (c *CommandInfo) prepareAndValidate() {
109110 }
110111}
111112
113+ // NewCmd returns a new CommandInfo with the Name field set to name and Path field set to
114+ // a single element slice of name. This function will panic if name is empty or contains
115+ // whitespace.
112116func NewCmd (name string ) CommandInfo {
113117 // assert command name isn't empty and doesn't contain any whitespace
114118 if name == "" {
115119 panic (errEmptyCmdName )
116120 }
117- for i := range name {
118- switch name [i ] {
119- case ' ' , '\t' , '\n' , '\r' :
120- panic ("invalid command name '" + name + "': cannot contain whitespace" )
121- }
121+ if strings .ContainsFunc (name , unicode .IsSpace ) {
122+ panic ("invalid command name '" + name + "': cannot contain whitespace" )
122123 }
123-
124124 return CommandInfo {
125125 Name : name ,
126126 Path : []string {name },
127127 Opts : make ([]InputInfo , 0 , 5 ),
128128 }
129129}
130130
131+ // Help sets the HelpBlurb field of this command to blurb.
131132func (c CommandInfo ) Help (blurb string ) CommandInfo {
132133 c .HelpBlurb = blurb
133134 return c
You can’t perform that action at this time.
0 commit comments