@@ -16,12 +16,12 @@ var (
1616 errReqArgAfterOptional = "required positional arguments cannot come after optional ones"
1717)
1818
19- func (c Command ) Build () * RootCommand {
19+ func (c CommandInfo ) Build () * RootCommandInfo {
2020 c .validate ()
21- return & RootCommand {c : c }
21+ return & RootCommandInfo {c : c }
2222}
2323
24- func (c * Command ) validate () {
24+ func (c * CommandInfo ) validate () {
2525 // option assertions
2626 for i := 0 ; i < len (c .opts )- 1 ; i ++ {
2727 for z := i + 1 ; z < len (c .opts ); z ++ {
@@ -105,7 +105,7 @@ func (e invalidCmdNameError) String() string {
105105 return "invalid command name '" + e .name + "': " + e .reason
106106}
107107
108- func NewCmd (name string ) Command {
108+ func NewCmd (name string ) CommandInfo {
109109 // assert command name isn't empty and doesn't contain any whitespace
110110 if name == "" {
111111 panic (errEmptyCmdName )
@@ -120,35 +120,35 @@ func NewCmd(name string) Command {
120120 }
121121 }
122122
123- c := Command {
123+ c := CommandInfo {
124124 name : name ,
125125 path : []string {name },
126- opts : make ([]Input , 0 , 5 ),
126+ opts : make ([]InputInfo , 0 , 5 ),
127127 }
128128 return c .Opt (DefaultHelpInput )
129129}
130130
131- func (c Command ) Help (blurb string ) Command {
131+ func (c CommandInfo ) Help (blurb string ) CommandInfo {
132132 c .helpBlurb = blurb
133133 return c
134134}
135135
136136// HelpExtra adds an "overview" section to the Command's help message. This is typically
137137// for longer-form content that wouldn't fit well within the 1-2 sentence "blurb."
138- func (c Command ) HelpExtra (extra string ) Command {
138+ func (c CommandInfo ) HelpExtra (extra string ) CommandInfo {
139139 c .helpExtra = extra
140140 return c
141141}
142142
143143// HelpUsage overrides the default "usage" lines in the command's help message. These are
144144// intended to show the user some different ways to invoke this command using whatever
145145// combinations of options / arguments / subcommands.
146- func (c Command ) HelpUsage (lines ... string ) Command {
146+ func (c CommandInfo ) HelpUsage (lines ... string ) CommandInfo {
147147 c .helpUsage = append (c .helpUsage , lines ... )
148148 return c
149149}
150150
151- func (c Command ) Opt (o Input ) Command {
151+ func (c CommandInfo ) Opt (o InputInfo ) CommandInfo {
152152 // Assert `o` is not a positional arg by making sure it has at least one option name.
153153 if o .nameShort == "" && o .nameLong == "" {
154154 panic (errEmptyOptNames )
@@ -157,7 +157,7 @@ func (c Command) Opt(o Input) Command {
157157 return c
158158}
159159
160- func (c Command ) Arg (a Input ) Command {
160+ func (c CommandInfo ) Arg (a InputInfo ) CommandInfo {
161161 if len (c .subcmds ) > 0 {
162162 panic (errMixingPosArgsAndSubcmds )
163163 }
@@ -174,7 +174,7 @@ func (c Command) Arg(a Input) Command {
174174 return c
175175}
176176
177- func (c Command ) Subcmd (sc Command ) Command {
177+ func (c CommandInfo ) Subcmd (sc CommandInfo ) CommandInfo {
178178 if len (c .args ) > 0 {
179179 panic (errMixingPosArgsAndSubcmds )
180180 }
@@ -190,118 +190,118 @@ func (c Command) Subcmd(sc Command) Command {
190190// receive the raw string of any provided value. If id is more than a single character
191191// long, it will be this option's long name. If id is only a single character, it will be
192192// this option's short name instead. In either case, the long name can be reset using the
193- // [Input .Long] method.
194- func NewOpt (id string ) Input {
193+ // [InputInfo .Long] method.
194+ func NewOpt (id string ) InputInfo {
195195 if id == "" {
196196 panic (errEmptyInputID )
197197 }
198198 if len (id ) == 1 {
199- return Input {id : id }.ShortOnly (id [0 ])
199+ return InputInfo {id : id }.ShortOnly (id [0 ])
200200 }
201- return Input {id : id }.Long (id )
201+ return InputInfo {id : id }.Long (id )
202202}
203203
204204// NewBoolOpt returns a new boolean option. If no value is provided to this option when
205205// parsing, it will have a "parsed" value of true. If any value is provided, the
206206// [ParseBool] value parser is used. Any other parser set by the user for this option will
207207// be ignored.
208- func NewBoolOpt (id string ) Input {
208+ func NewBoolOpt (id string ) InputInfo {
209209 o := NewOpt (id )
210210 o .isBoolOpt = true
211211 return o
212212}
213213
214214// NewIntOpt returns a new option that uses the [ParseInt] value parser.
215- func NewIntOpt (id string ) Input {
215+ func NewIntOpt (id string ) InputInfo {
216216 return NewOpt (id ).WithParser (ParseInt )
217217}
218218
219219// NewUintOpt returns a new option that uses the [ParseUint] value parser.
220- func NewUintOpt (id string ) Input {
220+ func NewUintOpt (id string ) InputInfo {
221221 return NewOpt (id ).WithParser (ParseUint )
222222}
223223
224224// NewFloat32Opt returns a new option that uses the [ParseFloat32] value parser.
225- func NewFloat32Opt (id string ) Input {
225+ func NewFloat32Opt (id string ) InputInfo {
226226 return NewOpt (id ).WithParser (ParseFloat32 )
227227}
228228
229229// NewFloat64Opt returns a new option that uses the [ParseFloat64] value parser.
230- func NewFloat64Opt (id string ) Input {
230+ func NewFloat64Opt (id string ) InputInfo {
231231 return NewOpt (id ).WithParser (ParseFloat64 )
232232}
233233
234234// NewArg returns a new positional argument input. By default, the arg's display name will
235- // be the provided id, but this can be overidden with [Input .ValueName] method.
236- func NewArg (id string ) Input {
235+ // be the provided id, but this can be overidden with [InputInfo .ValueName] method.
236+ func NewArg (id string ) InputInfo {
237237 if id == "" {
238238 panic (errEmptyInputID )
239239 }
240- return Input {id : id , valueName : id }
240+ return InputInfo {id : id , valueName : id }
241241}
242242
243- // WithParser sets the Input 's parser to the given [ValueParser]. This will override any
243+ // WithParser sets the InputInfo 's parser to the given [ValueParser]. This will override any
244244// parser that has been set up until this point. Providing nil as the parser will restore
245- // the default behavior of just using the plain string value when this Input is parsed.
246- func (in Input ) WithParser (vp ValueParser ) Input {
245+ // the default behavior of just using the plain string value when this InputInfo is parsed.
246+ func (in InputInfo ) WithParser (vp ValueParser ) InputInfo {
247247 in .valueParser = vp
248248 return in
249249}
250250
251251// Short sets this option's short name to the given character. In order to create an
252- // option that has a short name but no long name, see [Input .ShortOnly].
253- func (in Input ) Short (c byte ) Input {
252+ // option that has a short name but no long name, see [InputInfo .ShortOnly].
253+ func (in InputInfo ) Short (c byte ) InputInfo {
254254 in .nameShort = string (c )
255255 return in
256256}
257257
258258// ShortOnly sets this option's short name to the given character and removes any long
259259// name it may have had at this point. In order to create an option that has both a short
260- // and long name, see [Input .Short]. Use [Input .Long] to add a long name back.
261- func (in Input ) ShortOnly (c byte ) Input {
260+ // and long name, see [InputInfo .Short]. Use [InputInfo .Long] to add a long name back.
261+ func (in InputInfo ) ShortOnly (c byte ) InputInfo {
262262 in .nameLong = ""
263263 return in .Short (c )
264264}
265265
266- func (in Input ) Long (name string ) Input {
266+ func (in InputInfo ) Long (name string ) InputInfo {
267267 in .nameLong = name
268268 return in
269269}
270270
271- func (in Input ) Help (blurb string ) Input {
271+ func (in InputInfo ) Help (blurb string ) InputInfo {
272272 in .helpBlurb = blurb
273273 return in
274274}
275275
276- func (in Input ) Env (e string ) Input {
276+ func (in InputInfo ) Env (e string ) InputInfo {
277277 in .env = e
278278 return in
279279}
280280
281- func (in Input ) Required () Input {
281+ func (in InputInfo ) Required () InputInfo {
282282 in .isRequired = true
283283 return in
284284}
285285
286- // ValueName sets the display name of this Input 's argument value. For non-boolean
286+ // ValueName sets the display name of this InputInfo 's argument value. For non-boolean
287287// options, it's the argument of the option. For positional arguments, it's the argument
288288// name itself.
289- func (in Input ) ValueName (name string ) Input {
289+ func (in InputInfo ) ValueName (name string ) InputInfo {
290290 in .valueName = name
291291 return in
292292}
293293
294- func (in Input ) Default (v string ) Input {
294+ func (in InputInfo ) Default (v string ) InputInfo {
295295 in .rawDefaultValue = v
296296 in .hasDefaultValue = true
297297 return in
298298}
299299
300- func (in Input ) HelpGen (hg HelpGenerator ) Input {
300+ func (in InputInfo ) HelpGen (hg HelpGenerator ) InputInfo {
301301 in .helpGen = hg
302302 return in
303303}
304304
305- func (in * Input ) isOption () bool {
305+ func (in * InputInfo ) isOption () bool {
306306 return in .nameShort != "" || in .nameLong != ""
307307}
0 commit comments