Debian Codegraph @

set.go

raw symbols SCIP
1 // Copyright 2013 Google Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/
6
7 import (
8 "ioscip-go gomod github.com/golang/go/src go1.13 io/"
9 "osscip-go gomod github.com/golang/go/src go1.13 os/"
10 "sortscip-go gomod github.com/golang/go/src go1.13 sort/"
11 )
12
13 // A Termination says why Getopt returned.
14 type Statescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/State# int
15
16 const (
17 InProgressscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/InProgress. = Statescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/State#(iota) // Getopt is still running
18 Dashscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Dash. // Returned on "-"
19 DashDashscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/DashDash. // Returned on "--"
20 EndOfOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/EndOfOptions. // End of options reached
21 EndOfArgumentsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/EndOfArguments. // No more arguments
22 Terminatedscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Terminated. // Terminated by callback function
23 Failurescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Failure. // Terminated due to error
24 Unknownscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Unknown. // Indicates internal error
25 )
26
27 type Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set# struct {
28 Statescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#State. // State of getopt
29
30 // args are the parameters remaining after parsing the options.
31 argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args. []string
32
33 // program is the name of the program for usage and error messages.
34 // If not set it will automatically be set to the base name of the
35 // first argument passed to parse.
36 programscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#program. string
37
38 // parameters is what is displayed on the usage line after displaying
39 // the various options.
40 parametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#parameters. string
41
42 usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#usage. func() // usage should print the programs usage and exit.
43
44 shortOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#shortOptions. map[rune]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#
45 longOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#longOptions. map[string]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#
46 optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options. optionListscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/optionList#
47 }
48
49 // New returns a newly created option set.
50 func Newscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/New().() *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set# {
51 s := &Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#{
52 shortOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#shortOptions.: make(map[rune]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#),
53 longOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#longOptions.: make(map[string]*optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#),
54 parametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#parameters.: "[parameters ...]",
55 }
56
57 s.usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#usage. = func() {
58 s.PrintUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#PrintUsage().(stderrscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/stderr.)
59 }
60 return s
61 }
62
63 // The default set of command-line options.
64 var CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine. = Newscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/New().()
65
66 // PrintUsage calls PrintUsage in the default option set.
67 func PrintUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/PrintUsage().(w ioscip-go gomod github.com/golang/go/src go1.13 io/.Writerscip-go gomod github.com/golang/go/src go1.13 io/Writer#) { CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..PrintUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#PrintUsage().(w) }
68
69 // Usage calls the usage function in the default option set.
70 func Usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Usage().() { CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#usage.() }
71
72 // Parse calls Parse in the default option set with the command line arguments
73 // found in os.Args.
74 func Parsescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Parse().() { CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Parsescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Parse().(osscip-go gomod github.com/golang/go/src go1.13 os/.Argsscip-go gomod github.com/golang/go/src go1.13 os/Args.) }
75
76 // Getops returns the result of calling Getop in the default option set with the
77 // command line arguments found in os.Args. The fn function, which may be nil,
78 // is passed to Getopt.
79 func Getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Getopt().(fn func(Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#) bool) error { return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Getoptscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Getopt().(osscip-go gomod github.com/golang/go/src go1.13 os/.Argsscip-go gomod github.com/golang/go/src go1.13 os/Args., fn) }
80
81 // Arg returns the n'th command-line argument. Arg(0) is the first remaining
82 // argument after options have been processed.
83 func Argscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Arg().(n int) string {
84 if n >= 0 && n < len(CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.) {
85 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.[n]
86 }
87 return ""
88 }
89
90 // Arg returns the n'th argument. Arg(0) is the first remaining
91 // argument after options have been processed.
92 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Argscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Arg().(n int) string {
93 if n >= 0 && n < len(s.argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.) {
94 return s.argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.[n]
95 }
96 return ""
97 }
98
99 // Args returns the non-option command line arguments.
100 func Argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Args().() []string {
101 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.
102 }
103
104 // Args returns the non-option arguments.
105 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Args().() []string {
106 return s.argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.
107 }
108
109 // NArgs returns the number of non-option command line arguments.
110 func NArgsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/NArgs().() int {
111 return len(CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.)
112 }
113
114 // NArgs returns the number of non-option arguments.
115 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) NArgsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#NArgs().() int {
116 return len(s.argsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#args.)
117 }
118
119 // SetParameters sets the parameters string for printing the command line
120 // usage. It defaults to "[parameters ...]"
121 func SetParametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/SetParameters().(parameters string) {
122 CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..parametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#parameters. = parameters
123 }
124
125 // SetParameters sets the parameters string for printing the s's usage.
126 // It defaults to "[parameters ...]"
127 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) SetParametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#SetParameters().(parameters string) {
128 s.parametersscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#parameters. = parameters
129 }
130
131 // SetProgram sets the program name to program. Nomrally it is determined
132 // from the zeroth command line argument (see os.Args).
133 func SetProgramscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/SetProgram().(program string) {
134 CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..programscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#program. = program
135 }
136
137 // SetProgram sets s's program name to program. Nomrally it is determined
138 // from the zeroth argument passed to Getopt or Parse.
139 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) SetProgramscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#SetProgram().(program string) {
140 s.programscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#program. = program
141 }
142
143 // SetUsage sets the function used by Parse to display the commands usage
144 // on error. It defaults to calling PrintUsage(os.Stderr).
145 func SetUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/SetUsage().(usage func()) {
146 CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#usage. = usage
147 }
148
149 // SetUsage sets the function used by Parse to display usage on error. It
150 // defaults to calling f.PrintUsage(os.Stderr).
151 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) SetUsagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#SetUsage().(usage func()) {
152 s.usagescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#usage. = usage
153 }
154
155 // Lookup returns the Option associated with name. Name should either be
156 // a rune (the short name) or a string (the long name).
157 func Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Lookup().(name interface{}) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# {
158 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Lookup().(name)
159 }
160
161 // Lookup returns the Option associated with name in s. Name should either be
162 // a rune (the short name) or a string (the long name).
163 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Lookup().(name interface{}) Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option# {
164 switch v := name.(type) {
165 case rune:
166 return s.shortOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#shortOptions.[v]
167 case int:
168 return s.shortOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#shortOptions.[rune(v)]
169 case string:
170 return s.longOptionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#longOptions.[v]
171 }
172 return nil
173 }
174
175 // IsSet returns true if the Option associated with name was seen while
176 // parsing the command line arguments. Name should either be a rune (the
177 // short name) or a string (the long name).
178 func IsSetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/IsSet().(name interface{}) bool {
179 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..IsSetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#IsSet().(name)
180 }
181
182 // IsSet returns true if the Option associated with name was seen while
183 // parsing s. Name should either be a rune (the short name) or a string (the
184 // long name).
185 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) IsSetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#IsSet().(name interface{}) bool {
186 if opt := s.Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Lookup().(name); opt != nil {
187 return opt.Seenscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Seen.()
188 }
189 return false
190 }
191
192 // GetCount returns the number of times the Option associated with name has been
193 // seen while parsing the command line arguments. Name should either be a rune
194 // (the short name) or a string (the long name).
195 func GetCountscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/GetCount().(name interface{}) int {
196 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..GetCountscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#GetCount().(name)
197 }
198
199 // GetCount returns the number of times the Option associated with name has been
200 // seen while parsing s's arguments. Name should either be a rune (the short
201 // name) or a string (the long name).
202 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) GetCountscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#GetCount().(name interface{}) int {
203 if opt := s.Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Lookup().(name); opt != nil {
204 return opt.Countscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#Count.()
205 }
206 return 0
207 }
208
209 // GetValue returns the final value set to the command-line Option with name.
210 // If the option has not been seen while parsing s then the default value is
211 // returned. Name should either be a rune (the short name) or a string (the
212 // long name).
213 func GetValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/GetValue().(name interface{}) string {
214 return CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..GetValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#GetValue().(name)
215 }
216
217 // GetValue returns the final value set to the Option in s associated with name.
218 // If the option has not been seen while parsing s then the default value is
219 // returned. Name should either be a rune (the short name) or a string (the
220 // long name).
221 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) GetValuescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#GetValue().(name interface{}) string {
222 if opt := s.Lookupscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Lookup().(name); opt != nil {
223 return opt.Stringscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#String.()
224 }
225 return ""
226 }
227
228 // Visit visits the command-line options in lexicographical order, calling fn
229 // for each. It visits only those options that have been set.
230 func Visitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Visit().(fn func(Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#)) { CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Visitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Visit().(fn) }
231
232 // Visit visits the options in s in lexicographical order, calling fn
233 // for each. It visits only those options that have been set.
234 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Visitscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Visit().(fn func(Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#)) {
235 sortscip-go gomod github.com/golang/go/src go1.13 sort/.Sortscip-go gomod github.com/golang/go/src go1.13 sort/Sort().(s.optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options.)
236 for _, opt := range s.optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options. {
237 if opt.countscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#count. > 0 {
238 fn(opt)
239 }
240 }
241 }
242
243 // VisitAll visits the options in s in lexicographical order, calling fn
244 // for each. It visits all options, even those not set.
245 func VisitAllscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/VisitAll().(fn func(Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#)) { CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..VisitAllscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#VisitAll().(fn) }
246
247 // VisitAll visits the command-line flags in lexicographical order, calling fn
248 // for each. It visits all flags, even those not set.
249 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) VisitAllscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#VisitAll().(fn func(Optionscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Option#)) {
250 sortscip-go gomod github.com/golang/go/src go1.13 sort/.Sortscip-go gomod github.com/golang/go/src go1.13 sort/Sort().(s.optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options.)
251 for _, opt := range s.optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options. {
252 fn(opt)
253 }
254 }
255
256 // Reset resets all the command line options to the initial state so it
257 // appears none of them have been seen.
258 func Resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Reset().() {
259 CommandLinescip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/CommandLine..Resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Reset().()
260 }
261
262 // Reset resets all the options in s to the initial state so it
263 // appears none of them have been seen.
264 func (s *Setscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#) Resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#Reset().() {
265 for _, opt := range s.optionsscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/Set#options. {
266 opt.Resetscip-go gomod github.com/pborman/getopt . `github.com/pborman/getopt`/option#Reset().()
267 }
268 }