File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff 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.
282284func (in InputInfo ) Env (e string ) InputInfo {
283285 in .EnvVar = e
284286 return in
Original file line number Diff line number Diff line change 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+
102115func ExampleInputInfo_Long () {
103116 in := cli .New ("example" ).
104117 Help ("example program" ).
You can’t perform that action at this time.
0 commit comments