Skip to content

Commit ca31a1c

Browse files
committed
docs: add doc and example for InputInfo.Long method
1 parent 04722ef commit ca31a1c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ func (in InputInfo) ShortOnly(c byte) InputInfo {
257257
return in.Short(c)
258258
}
259259

260+
// Long sets the option long name to the given name. Since an option's long name will be
261+
// the input ID by default, this method is really only necessary when the long name must
262+
// differ from the input ID.
260263
func (in InputInfo) Long(name string) InputInfo {
261264
in.NameLong = name
262265
return in

examples_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ func ExampleInputInfo_WithParser() {
9999
// image.Point{X:3, Y:7}
100100
}
101101

102+
func ExampleInputInfo_Long() {
103+
in := cli.New("example").
104+
Help("example program").
105+
Opt(cli.NewOpt("id1").Help("long name is the id by default")).
106+
Opt(cli.NewOpt("id2").Long("long-name").Help("long name is set to something other than the id"))
107+
108+
_, err := in.Parse("-h")
109+
fmt.Println(err)
110+
// Output:
111+
// example - example program
112+
//
113+
// usage:
114+
// example [options]
115+
//
116+
// options:
117+
// -h, --help Show this help message and exit.
118+
// --id1 <arg> long name is the id by default
119+
// --long-name <arg> long name is set to something other than the id
120+
}
121+
102122
func ExampleParseURL() {
103123
in := cli.New().
104124
Opt(cli.NewOpt("u").WithParser(cli.ParseURL))

0 commit comments

Comments
 (0)