Skip to content

Commit 9418245

Browse files
committed
docs: comment and example for InputInfo.Env
1 parent a29cb3a commit 9418245

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

builder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func (in InputInfo) Help(blurb string) InputInfo {
279279
return in
280280
}
281281

282+
// Env sets the name of the environment variable for this InputInfo. The parser will parse
283+
// the value of that environment variable for this input if it is set.
282284
func (in InputInfo) Env(e string) InputInfo {
283285
in.EnvVar = e
284286
return in

examples_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"image"
66
"net/url"
7+
"os"
78
"strconv"
89
"strings"
910
"time"
@@ -99,6 +100,18 @@ func ExampleInputInfo_WithParser() {
99100
// image.Point{X:3, Y:7}
100101
}
101102

103+
func ExampleInputInfo_Env() {
104+
os.Setenv("FLAG", "hello")
105+
106+
c := cli.New().
107+
Opt(cli.NewOpt("flag").Env("FLAG")).
108+
ParseOrExit([]string{}...)
109+
110+
fmt.Println(cli.Get[string](c, "flag"))
111+
// Output:
112+
// hello
113+
}
114+
102115
func ExampleInputInfo_Long() {
103116
in := cli.New("example").
104117
Help("example program").

0 commit comments

Comments
 (0)