File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -144,6 +144,9 @@ func (c CommandInfo) Usage(lines ...string) CommandInfo {
144144 return c
145145}
146146
147+ // Opt adds o as an option to this CommandInfo. This method will panic if the option has
148+ // neither a long or short name set (this should never happen when using the builder
149+ // pattern starting with the [NewOpt] function or its siblings).
147150func (c CommandInfo ) Opt (o InputInfo ) CommandInfo {
148151 // Assert `o` is not a positional arg by making sure it has at least one option name.
149152 if o .NameShort == "" && o .NameLong == "" {
Original file line number Diff line number Diff line change @@ -196,6 +196,16 @@ func ExampleCommandInfo_Arg() {
196196 // alice
197197}
198198
199+ func ExampleCommandInfo_Opt () {
200+ c := cli .New ().
201+ Opt (cli .NewOpt ("a" )).
202+ ParseOrExit ("-a" , "hello" )
203+
204+ fmt .Println (cli .Get [string ](c , "a" ))
205+ // Output:
206+ // hello
207+ }
208+
199209func ExampleCommandInfo_ExtraHelp () {
200210 in := cli .New ("example" ).
201211 Help ("an example command" ).
You can’t perform that action at this time.
0 commit comments