You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1561 lines
56 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>flag - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package flag</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "flag"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd>
  58. </dl>
  59. </div>
  60. <!-- The package's Name is printed as title by the top-level template -->
  61. <div id="pkg-overview" class="toggleVisible">
  62. <div class="collapsed">
  63. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  64. </div>
  65. <div class="expanded">
  66. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  67. <p>
  68. Package flag implements command-line flag parsing.
  69. </p>
  70. <p>
  71. Usage:
  72. </p>
  73. <p>
  74. Define flags using flag.String(), Bool(), Int(), etc.
  75. </p>
  76. <p>
  77. This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
  78. </p>
  79. <pre>import &#34;flag&#34;
  80. var ip = flag.Int(&#34;flagname&#34;, 1234, &#34;help message for flagname&#34;)
  81. </pre>
  82. <p>
  83. If you like, you can bind the flag to a variable using the Var() functions.
  84. </p>
  85. <pre>var flagvar int
  86. func init() {
  87. flag.IntVar(&amp;flagvar, &#34;flagname&#34;, 1234, &#34;help message for flagname&#34;)
  88. }
  89. </pre>
  90. <p>
  91. Or you can create custom flags that satisfy the Value interface (with
  92. pointer receivers) and couple them to flag parsing by
  93. </p>
  94. <pre>flag.Var(&amp;flagVal, &#34;name&#34;, &#34;help message for flagname&#34;)
  95. </pre>
  96. <p>
  97. For such flags, the default value is just the initial value of the variable.
  98. </p>
  99. <p>
  100. After all flags are defined, call
  101. </p>
  102. <pre>flag.Parse()
  103. </pre>
  104. <p>
  105. to parse the command line into the defined flags.
  106. </p>
  107. <p>
  108. Flags may then be used directly. If you&#39;re using the flags themselves,
  109. they are all pointers; if you bind to variables, they&#39;re values.
  110. </p>
  111. <pre>fmt.Println(&#34;ip has value &#34;, *ip)
  112. fmt.Println(&#34;flagvar has value &#34;, flagvar)
  113. </pre>
  114. <p>
  115. After parsing, the arguments following the flags are available as the
  116. slice flag.Args() or individually as flag.Arg(i).
  117. The arguments are indexed from 0 through flag.NArg()-1.
  118. </p>
  119. <p>
  120. Command line flag syntax:
  121. </p>
  122. <pre>-flag
  123. -flag=x
  124. -flag x // non-boolean flags only
  125. </pre>
  126. <p>
  127. One or two minus signs may be used; they are equivalent.
  128. The last form is not permitted for boolean flags because the
  129. meaning of the command
  130. </p>
  131. <pre>cmd -x *
  132. </pre>
  133. <p>
  134. will change if there is a file called 0, false, etc. You must
  135. use the -flag=false form to turn off a boolean flag.
  136. </p>
  137. <p>
  138. Flag parsing stops just before the first non-flag argument
  139. (&#34;-&#34; is a non-flag argument) or after the terminator &#34;--&#34;.
  140. </p>
  141. <p>
  142. Integer flags accept 1234, 0664, 0x1234 and may be negative.
  143. Boolean flags may be:
  144. </p>
  145. <pre>1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False
  146. </pre>
  147. <p>
  148. Duration flags accept any input valid for time.ParseDuration.
  149. </p>
  150. <p>
  151. The default set of command-line flags is controlled by
  152. top-level functions. The FlagSet type allows one to define
  153. independent sets of flags, such as to implement subcommands
  154. in a command-line interface. The methods of FlagSet are
  155. analogous to the top-level functions for the command-line
  156. flag set.
  157. </p>
  158. </div>
  159. </div>
  160. <div id="example_" class="toggle">
  161. <div class="collapsed">
  162. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  163. </div>
  164. <div class="expanded">
  165. <p class="exampleHeading toggleButton"><span class="text">Example</span></p>
  166. <p>Code:</p>
  167. <pre class="code"><span class="comment">// These examples demonstrate more intricate uses of the flag package.</span>
  168. package flag_test
  169. import (
  170. &#34;errors&#34;
  171. &#34;flag&#34;
  172. &#34;fmt&#34;
  173. &#34;strings&#34;
  174. &#34;time&#34;
  175. )
  176. <span class="comment">// Example 1: A single string flag called &#34;species&#34; with default value &#34;gopher&#34;.</span>
  177. var species = flag.String(&#34;species&#34;, &#34;gopher&#34;, &#34;the species we are studying&#34;)
  178. <span class="comment">// Example 2: Two flags sharing a variable, so we can have a shorthand.</span>
  179. <span class="comment">// The order of initialization is undefined, so make sure both use the</span>
  180. <span class="comment">// same default value. They must be set up with an init function.</span>
  181. var gopherType string
  182. func init() {
  183. const (
  184. defaultGopher = &#34;pocket&#34;
  185. usage = &#34;the variety of gopher&#34;
  186. )
  187. flag.StringVar(&amp;gopherType, &#34;gopher_type&#34;, defaultGopher, usage)
  188. flag.StringVar(&amp;gopherType, &#34;g&#34;, defaultGopher, usage+&#34; (shorthand)&#34;)
  189. }
  190. <span class="comment">// Example 3: A user-defined flag type, a slice of durations.</span>
  191. type interval []time.Duration
  192. <span class="comment">// String is the method to format the flag&#39;s value, part of the flag.Value interface.</span>
  193. <span class="comment">// The String method&#39;s output will be used in diagnostics.</span>
  194. func (i *interval) String() string {
  195. return fmt.Sprint(*i)
  196. }
  197. <span class="comment">// Set is the method to set the flag value, part of the flag.Value interface.</span>
  198. <span class="comment">// Set&#39;s argument is a string to be parsed to set the flag.</span>
  199. <span class="comment">// It&#39;s a comma-separated list, so we split it.</span>
  200. func (i *interval) Set(value string) error {
  201. <span class="comment">// If we wanted to allow the flag to be set multiple times,</span>
  202. <span class="comment">// accumulating values, we would delete this if statement.</span>
  203. <span class="comment">// That would permit usages such as</span>
  204. <span class="comment">// -deltaT 10s -deltaT 15s</span>
  205. <span class="comment">// and other combinations.</span>
  206. if len(*i) &gt; 0 {
  207. return errors.New(&#34;interval flag already set&#34;)
  208. }
  209. for _, dt := range strings.Split(value, &#34;,&#34;) {
  210. duration, err := time.ParseDuration(dt)
  211. if err != nil {
  212. return err
  213. }
  214. *i = append(*i, duration)
  215. }
  216. return nil
  217. }
  218. <span class="comment">// Define a flag to accumulate durations. Because it has a special type,</span>
  219. <span class="comment">// we need to use the Var function and therefore create the flag during</span>
  220. <span class="comment">// init.</span>
  221. var intervalFlag interval
  222. func init() {
  223. <span class="comment">// Tie the command-line flag to the intervalFlag variable and</span>
  224. <span class="comment">// set a usage message.</span>
  225. flag.Var(&amp;intervalFlag, &#34;deltaT&#34;, &#34;comma-separated list of intervals to use between events&#34;)
  226. }
  227. func Example() {
  228. <span class="comment">// All the interesting pieces are with the variables declared above, but</span>
  229. <span class="comment">// to enable the flag package to see the flags defined there, one must</span>
  230. <span class="comment">// execute, typically at the start of main (not init!):</span>
  231. <span class="comment">// flag.Parse()</span>
  232. <span class="comment">// We don&#39;t run it here because this is not a main function and</span>
  233. <span class="comment">// the testing suite has already parsed the flags.</span>
  234. }
  235. </pre>
  236. </div>
  237. </div>
  238. <div id="pkg-index" class="toggleVisible">
  239. <div class="collapsed">
  240. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  241. </div>
  242. <div class="expanded">
  243. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  244. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  245. <div id="manual-nav">
  246. <dl>
  247. <dd><a href="index.html#pkg-variables">Variables</a></dd>
  248. <dd><a href="index.html#Arg">func Arg(i int) string</a></dd>
  249. <dd><a href="index.html#Args">func Args() []string</a></dd>
  250. <dd><a href="index.html#Bool">func Bool(name string, value bool, usage string) *bool</a></dd>
  251. <dd><a href="index.html#BoolVar">func BoolVar(p *bool, name string, value bool, usage string)</a></dd>
  252. <dd><a href="index.html#Duration">func Duration(name string, value time.Duration, usage string) *time.Duration</a></dd>
  253. <dd><a href="index.html#DurationVar">func DurationVar(p *time.Duration, name string, value time.Duration, usage string)</a></dd>
  254. <dd><a href="index.html#Float64">func Float64(name string, value float64, usage string) *float64</a></dd>
  255. <dd><a href="index.html#Float64Var">func Float64Var(p *float64, name string, value float64, usage string)</a></dd>
  256. <dd><a href="index.html#Int">func Int(name string, value int, usage string) *int</a></dd>
  257. <dd><a href="index.html#Int64">func Int64(name string, value int64, usage string) *int64</a></dd>
  258. <dd><a href="index.html#Int64Var">func Int64Var(p *int64, name string, value int64, usage string)</a></dd>
  259. <dd><a href="index.html#IntVar">func IntVar(p *int, name string, value int, usage string)</a></dd>
  260. <dd><a href="index.html#NArg">func NArg() int</a></dd>
  261. <dd><a href="index.html#NFlag">func NFlag() int</a></dd>
  262. <dd><a href="index.html#Parse">func Parse()</a></dd>
  263. <dd><a href="index.html#Parsed">func Parsed() bool</a></dd>
  264. <dd><a href="index.html#PrintDefaults">func PrintDefaults()</a></dd>
  265. <dd><a href="index.html#Set">func Set(name, value string) error</a></dd>
  266. <dd><a href="index.html#String">func String(name string, value string, usage string) *string</a></dd>
  267. <dd><a href="index.html#StringVar">func StringVar(p *string, name string, value string, usage string)</a></dd>
  268. <dd><a href="index.html#Uint">func Uint(name string, value uint, usage string) *uint</a></dd>
  269. <dd><a href="index.html#Uint64">func Uint64(name string, value uint64, usage string) *uint64</a></dd>
  270. <dd><a href="index.html#Uint64Var">func Uint64Var(p *uint64, name string, value uint64, usage string)</a></dd>
  271. <dd><a href="index.html#UintVar">func UintVar(p *uint, name string, value uint, usage string)</a></dd>
  272. <dd><a href="index.html#UnquoteUsage">func UnquoteUsage(flag *Flag) (name string, usage string)</a></dd>
  273. <dd><a href="index.html#Var">func Var(value Value, name string, usage string)</a></dd>
  274. <dd><a href="index.html#Visit">func Visit(fn func(*Flag))</a></dd>
  275. <dd><a href="index.html#VisitAll">func VisitAll(fn func(*Flag))</a></dd>
  276. <dd><a href="index.html#ErrorHandling">type ErrorHandling</a></dd>
  277. <dd><a href="index.html#Flag">type Flag</a></dd>
  278. <dd>&nbsp; &nbsp; <a href="index.html#Lookup">func Lookup(name string) *Flag</a></dd>
  279. <dd><a href="index.html#FlagSet">type FlagSet</a></dd>
  280. <dd>&nbsp; &nbsp; <a href="index.html#NewFlagSet">func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet</a></dd>
  281. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Arg">func (f *FlagSet) Arg(i int) string</a></dd>
  282. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Args">func (f *FlagSet) Args() []string</a></dd>
  283. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Bool">func (f *FlagSet) Bool(name string, value bool, usage string) *bool</a></dd>
  284. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.BoolVar">func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)</a></dd>
  285. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Duration">func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration</a></dd>
  286. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.DurationVar">func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)</a></dd>
  287. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Float64">func (f *FlagSet) Float64(name string, value float64, usage string) *float64</a></dd>
  288. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Float64Var">func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)</a></dd>
  289. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Init">func (f *FlagSet) Init(name string, errorHandling ErrorHandling)</a></dd>
  290. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Int">func (f *FlagSet) Int(name string, value int, usage string) *int</a></dd>
  291. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Int64">func (f *FlagSet) Int64(name string, value int64, usage string) *int64</a></dd>
  292. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Int64Var">func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)</a></dd>
  293. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.IntVar">func (f *FlagSet) IntVar(p *int, name string, value int, usage string)</a></dd>
  294. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Lookup">func (f *FlagSet) Lookup(name string) *Flag</a></dd>
  295. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.NArg">func (f *FlagSet) NArg() int</a></dd>
  296. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.NFlag">func (f *FlagSet) NFlag() int</a></dd>
  297. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Parse">func (f *FlagSet) Parse(arguments []string) error</a></dd>
  298. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Parsed">func (f *FlagSet) Parsed() bool</a></dd>
  299. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.PrintDefaults">func (f *FlagSet) PrintDefaults()</a></dd>
  300. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Set">func (f *FlagSet) Set(name, value string) error</a></dd>
  301. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.SetOutput">func (f *FlagSet) SetOutput(output io.Writer)</a></dd>
  302. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.String">func (f *FlagSet) String(name string, value string, usage string) *string</a></dd>
  303. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.StringVar">func (f *FlagSet) StringVar(p *string, name string, value string, usage string)</a></dd>
  304. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Uint">func (f *FlagSet) Uint(name string, value uint, usage string) *uint</a></dd>
  305. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Uint64">func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64</a></dd>
  306. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Uint64Var">func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)</a></dd>
  307. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.UintVar">func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)</a></dd>
  308. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Var">func (f *FlagSet) Var(value Value, name string, usage string)</a></dd>
  309. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.Visit">func (f *FlagSet) Visit(fn func(*Flag))</a></dd>
  310. <dd>&nbsp; &nbsp; <a href="index.html#FlagSet.VisitAll">func (f *FlagSet) VisitAll(fn func(*Flag))</a></dd>
  311. <dd><a href="index.html#Getter">type Getter</a></dd>
  312. <dd><a href="index.html#Value">type Value</a></dd>
  313. </dl>
  314. </div><!-- #manual-nav -->
  315. <div id="pkg-examples">
  316. <h4>Examples</h4>
  317. <dl>
  318. <dd><a class="exampleLink" href="index.html#example_">Package</a></dd>
  319. </dl>
  320. </div>
  321. <h4>Package files</h4>
  322. <p>
  323. <span style="font-size:90%">
  324. <a href="http://localhost:6060/src/flag/flag.go">flag.go</a>
  325. </span>
  326. </p>
  327. </div><!-- .expanded -->
  328. </div><!-- #pkg-index -->
  329. <div id="pkg-callgraph" class="toggle" style="display: none">
  330. <div class="collapsed">
  331. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  332. </div> <!-- .expanded -->
  333. <div class="expanded">
  334. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  335. <p>
  336. In the call graph viewer below, each node
  337. is a function belonging to this package
  338. and its children are the functions it
  339. calls&mdash;perhaps dynamically.
  340. </p>
  341. <p>
  342. The root nodes are the entry points of the
  343. package: functions that may be called from
  344. outside the package.
  345. There may be non-exported or anonymous
  346. functions among them if they are called
  347. dynamically from another package.
  348. </p>
  349. <p>
  350. Click a node to visit that function's source code.
  351. From there you can visit its callers by
  352. clicking its declaring <code>func</code>
  353. token.
  354. </p>
  355. <p>
  356. Functions may be omitted if they were
  357. determined to be unreachable in the
  358. particular programs or tests that were
  359. analyzed.
  360. </p>
  361. <!-- Zero means show all package entry points. -->
  362. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  363. </div>
  364. </div> <!-- #pkg-callgraph -->
  365. <h2 id="pkg-variables">Variables</h2>
  366. <pre>var <span id="CommandLine">CommandLine</span> = <a href="index.html#NewFlagSet">NewFlagSet</a>(<a href="../os/index.html">os</a>.<a href="../os/index.html#Args">Args</a>[0], <a href="index.html#ExitOnError">ExitOnError</a>)</pre>
  367. <p>
  368. CommandLine is the default set of command-line flags, parsed from os.Args.
  369. The top-level functions such as BoolVar, Arg, and so on are wrappers for the
  370. methods of CommandLine.
  371. </p>
  372. <pre>var <span id="ErrHelp">ErrHelp</span> = <a href="../errors/index.html">errors</a>.<a href="../errors/index.html#New">New</a>(&#34;flag: help requested&#34;)</pre>
  373. <p>
  374. ErrHelp is the error returned if the -help or -h flag is invoked
  375. but no such flag is defined.
  376. </p>
  377. <pre>var <span id="Usage">Usage</span> = func() {
  378. <a href="../fmt/index.html">fmt</a>.<a href="../fmt/index.html#Fprintf">Fprintf</a>(<a href="../os/index.html">os</a>.<a href="../os/index.html#Stderr">Stderr</a>, &#34;Usage of %s:\n&#34;, <a href="../os/index.html">os</a>.<a href="../os/index.html#Args">Args</a>[0])
  379. <a href="index.html#PrintDefaults">PrintDefaults</a>()
  380. }</pre>
  381. <p>
  382. Usage prints to standard error a usage message documenting all defined command-line flags.
  383. It is called when an error occurs while parsing flags.
  384. The function is a variable that may be changed to point to a custom function.
  385. By default it prints a simple header and calls PrintDefaults; for details about the
  386. format of the output and how to control it, see the documentation for PrintDefaults.
  387. </p>
  388. <h2 id="Arg">func <a href="http://localhost:6060/src/flag/flag.go?s=15279:15301#L520">Arg</a></h2>
  389. <pre>func Arg(i <a href="../builtin/index.html#int">int</a>) <a href="../builtin/index.html#string">string</a></pre>
  390. <p>
  391. Arg returns the i&#39;th command-line argument. Arg(0) is the first remaining argument
  392. after flags have been processed. Arg returns an empty string if the
  393. requested element does not exist.
  394. </p>
  395. <h2 id="Args">func <a href="http://localhost:6060/src/flag/flag.go?s=15739:15759#L534">Args</a></h2>
  396. <pre>func Args() []<a href="../builtin/index.html#string">string</a></pre>
  397. <p>
  398. Args returns the non-flag command-line arguments.
  399. </p>
  400. <h2 id="Bool">func <a href="http://localhost:6060/src/flag/flag.go?s=16847:16901#L558">Bool</a></h2>
  401. <pre>func Bool(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#bool">bool</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#bool">bool</a></pre>
  402. <p>
  403. Bool defines a bool flag with specified name, default value, and usage string.
  404. The return value is the address of a bool variable that stores the value of the flag.
  405. </p>
  406. <h2 id="BoolVar">func <a href="http://localhost:6060/src/flag/flag.go?s=16252:16312#L544">BoolVar</a></h2>
  407. <pre>func BoolVar(p *<a href="../builtin/index.html#bool">bool</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#bool">bool</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  408. <p>
  409. BoolVar defines a bool flag with specified name, default value, and usage string.
  410. The argument p points to a bool variable in which to store the value of the flag.
  411. </p>
  412. <h2 id="Duration">func <a href="http://localhost:6060/src/flag/flag.go?s=25633:25709#L744">Duration</a></h2>
  413. <pre>func Duration(name <a href="../builtin/index.html#string">string</a>, value <a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a></pre>
  414. <p>
  415. Duration defines a time.Duration flag with specified name, default value, and usage string.
  416. The return value is the address of a time.Duration variable that stores the value of the flag.
  417. The flag accepts a value acceptable to time.ParseDuration.
  418. </p>
  419. <h2 id="DurationVar">func <a href="http://localhost:6060/src/flag/flag.go?s=24809:24891#L728">DurationVar</a></h2>
  420. <pre>func DurationVar(p *<a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  421. <p>
  422. DurationVar defines a time.Duration flag with specified name, default value, and usage string.
  423. The argument p points to a time.Duration variable in which to store the value of the flag.
  424. The flag accepts a value acceptable to time.ParseDuration.
  425. </p>
  426. <h2 id="Float64">func <a href="http://localhost:6060/src/flag/flag.go?s=24035:24098#L714">Float64</a></h2>
  427. <pre>func Float64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#float64">float64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#float64">float64</a></pre>
  428. <p>
  429. Float64 defines a float64 flag with specified name, default value, and usage string.
  430. The return value is the address of a float64 variable that stores the value of the flag.
  431. </p>
  432. <h2 id="Float64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=23395:23464#L700">Float64Var</a></h2>
  433. <pre>func Float64Var(p *<a href="../builtin/index.html#float64">float64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#float64">float64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  434. <p>
  435. Float64Var defines a float64 flag with specified name, default value, and usage string.
  436. The argument p points to a float64 variable in which to store the value of the flag.
  437. </p>
  438. <h2 id="Int">func <a href="http://localhost:6060/src/flag/flag.go?s=17993:18044#L584">Int</a></h2>
  439. <pre>func Int(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int">int</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#int">int</a></pre>
  440. <p>
  441. Int defines an int flag with specified name, default value, and usage string.
  442. The return value is the address of an int variable that stores the value of the flag.
  443. </p>
  444. <h2 id="Int64">func <a href="http://localhost:6060/src/flag/flag.go?s=19185:19242#L610">Int64</a></h2>
  445. <pre>func Int64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int64">int64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#int64">int64</a></pre>
  446. <p>
  447. Int64 defines an int64 flag with specified name, default value, and usage string.
  448. The return value is the address of an int64 variable that stores the value of the flag.
  449. </p>
  450. <h2 id="Int64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=18571:18634#L596">Int64Var</a></h2>
  451. <pre>func Int64Var(p *<a href="../builtin/index.html#int64">int64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int64">int64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  452. <p>
  453. Int64Var defines an int64 flag with specified name, default value, and usage string.
  454. The argument p points to an int64 variable in which to store the value of the flag.
  455. </p>
  456. <h2 id="IntVar">func <a href="http://localhost:6060/src/flag/flag.go?s=17409:17466#L570">IntVar</a></h2>
  457. <pre>func IntVar(p *<a href="../builtin/index.html#int">int</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int">int</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  458. <p>
  459. IntVar defines an int flag with specified name, default value, and usage string.
  460. The argument p points to an int variable in which to store the value of the flag.
  461. </p>
  462. <h2 id="NArg">func <a href="http://localhost:6060/src/flag/flag.go?s=15543:15558#L528">NArg</a></h2>
  463. <pre>func NArg() <a href="../builtin/index.html#int">int</a></pre>
  464. <p>
  465. NArg is the number of arguments remaining after flags have been processed.
  466. </p>
  467. <h2 id="NFlag">func <a href="http://localhost:6060/src/flag/flag.go?s=14743:14759#L505">NFlag</a></h2>
  468. <pre>func NFlag() <a href="../builtin/index.html#int">int</a></pre>
  469. <p>
  470. NFlag returns the number of command-line flags that have been set.
  471. </p>
  472. <h2 id="Parse">func <a href="http://localhost:6060/src/flag/flag.go?s=30682:30694#L916">Parse</a></h2>
  473. <pre>func Parse()</pre>
  474. <p>
  475. Parse parses the command-line flags from os.Args[1:]. Must be called
  476. after all flags are defined and before flags are accessed by the program.
  477. </p>
  478. <h2 id="Parsed">func <a href="http://localhost:6060/src/flag/flag.go?s=30854:30872#L922">Parsed</a></h2>
  479. <pre>func Parsed() <a href="../builtin/index.html#bool">bool</a></pre>
  480. <p>
  481. Parsed reports whether the command-line flags have been parsed.
  482. </p>
  483. <h2 id="PrintDefaults">func <a href="http://localhost:6060/src/flag/flag.go?s=13608:13628#L473">PrintDefaults</a></h2>
  484. <pre>func PrintDefaults()</pre>
  485. <p>
  486. PrintDefaults prints, to standard error unless configured otherwise,
  487. a usage message showing the default settings of all defined
  488. command-line flags.
  489. For an integer valued flag x, the default output has the form
  490. </p>
  491. <pre>-x int
  492. usage-message-for-x (default 7)
  493. </pre>
  494. <p>
  495. The usage message will appear on a separate line for anything but
  496. a bool flag with a one-byte name. For bool flags, the type is
  497. omitted and if the flag name is one byte the usage message appears
  498. on the same line. The parenthetical default is omitted if the
  499. default is the zero value for the type. The listed type, here int,
  500. can be changed by placing a back-quoted name in the flag&#39;s usage
  501. string; the first such item in the message is taken to be a parameter
  502. name to show in the message and the back quotes are stripped from
  503. the message when displayed. For instance, given
  504. </p>
  505. <pre>flag.String(&#34;I&#34;, &#34;&#34;, &#34;search `directory` for include files&#34;)
  506. </pre>
  507. <p>
  508. the output will be
  509. </p>
  510. <pre>-I directory
  511. search directory for include files.
  512. </pre>
  513. <h2 id="Set">func <a href="http://localhost:6060/src/flag/flag.go?s=10100:10134#L365">Set</a></h2>
  514. <pre>func Set(name, value <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a></pre>
  515. <p>
  516. Set sets the value of the named command-line flag.
  517. </p>
  518. <h2 id="String">func <a href="http://localhost:6060/src/flag/flag.go?s=22789:22849#L688">String</a></h2>
  519. <pre>func String(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#string">string</a></pre>
  520. <p>
  521. String defines a string flag with specified name, default value, and usage string.
  522. The return value is the address of a string variable that stores the value of the flag.
  523. </p>
  524. <h2 id="StringVar">func <a href="http://localhost:6060/src/flag/flag.go?s=22164:22230#L674">StringVar</a></h2>
  525. <pre>func StringVar(p *<a href="../builtin/index.html#string">string</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  526. <p>
  527. StringVar defines a string flag with specified name, default value, and usage string.
  528. The argument p points to a string variable in which to store the value of the flag.
  529. </p>
  530. <h2 id="Uint">func <a href="http://localhost:6060/src/flag/flag.go?s=20355:20409#L636">Uint</a></h2>
  531. <pre>func Uint(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint">uint</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#uint">uint</a></pre>
  532. <p>
  533. Uint defines a uint flag with specified name, default value, and usage string.
  534. The return value is the address of a uint variable that stores the value of the flag.
  535. </p>
  536. <h2 id="Uint64">func <a href="http://localhost:6060/src/flag/flag.go?s=21568:21628#L662">Uint64</a></h2>
  537. <pre>func Uint64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint64">uint64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#uint64">uint64</a></pre>
  538. <p>
  539. Uint64 defines a uint64 flag with specified name, default value, and usage string.
  540. The return value is the address of a uint64 variable that stores the value of the flag.
  541. </p>
  542. <h2 id="Uint64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=20943:21009#L648">Uint64Var</a></h2>
  543. <pre>func Uint64Var(p *<a href="../builtin/index.html#uint64">uint64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint64">uint64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  544. <p>
  545. Uint64Var defines a uint64 flag with specified name, default value, and usage string.
  546. The argument p points to a uint64 variable in which to store the value of the flag.
  547. </p>
  548. <h2 id="UintVar">func <a href="http://localhost:6060/src/flag/flag.go?s=19758:19818#L622">UintVar</a></h2>
  549. <pre>func UintVar(p *<a href="../builtin/index.html#uint">uint</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint">uint</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  550. <p>
  551. UintVar defines a uint flag with specified name, default value, and usage string.
  552. The argument p points to a uint variable in which to store the value of the flag.
  553. </p>
  554. <h2 id="UnquoteUsage">func <a href="http://localhost:6060/src/flag/flag.go?s=10786:10843#L388">UnquoteUsage</a></h2>
  555. <pre>func UnquoteUsage(flag *<a href="index.html#Flag">Flag</a>) (name <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  556. <p>
  557. UnquoteUsage extracts a back-quoted name from the usage
  558. string for a flag and returns it and the un-quoted usage.
  559. Given &#34;a `name` to show&#34; it returns (&#34;name&#34;, &#34;a name to show&#34;).
  560. If there are no back quotes, the name is an educated guess of the
  561. type of the flag&#39;s value, or the empty string if the flag is boolean.
  562. </p>
  563. <h2 id="Var">func <a href="http://localhost:6060/src/flag/flag.go?s=27248:27296#L780">Var</a></h2>
  564. <pre>func Var(value <a href="index.html#Value">Value</a>, name <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  565. <p>
  566. Var defines a flag with the specified name and usage string. The type and
  567. value of the flag are represented by the first argument, of type Value, which
  568. typically holds a user-defined implementation of Value. For instance, the
  569. caller could create a flag that turns a comma-separated string into a slice
  570. of strings by giving the slice the methods of Value; in particular, Set would
  571. decompose the comma-separated string into the slice.
  572. </p>
  573. <h2 id="Visit">func <a href="http://localhost:6060/src/flag/flag.go?s=9322:9348#L332">Visit</a></h2>
  574. <pre>func Visit(fn func(*<a href="index.html#Flag">Flag</a>))</pre>
  575. <p>
  576. Visit visits the command-line flags in lexicographical order, calling fn
  577. for each. It visits only those flags that have been set.
  578. </p>
  579. <h2 id="VisitAll">func <a href="http://localhost:6060/src/flag/flag.go?s=8898:8927#L318">VisitAll</a></h2>
  580. <pre>func VisitAll(fn func(*<a href="index.html#Flag">Flag</a>))</pre>
  581. <p>
  582. VisitAll visits the command-line flags in lexicographical order, calling
  583. fn for each. It visits all flags, even those not set.
  584. </p>
  585. <h2 id="ErrorHandling">type <a href="http://localhost:6060/src/flag/flag.go?s=6739:6761#L245">ErrorHandling</a></h2>
  586. <pre>type ErrorHandling <a href="../builtin/index.html#int">int</a></pre>
  587. <p>
  588. ErrorHandling defines how FlagSet.Parse behaves if the parse fails.
  589. </p>
  590. <pre>const (
  591. <span id="ContinueOnError">ContinueOnError</span> <a href="index.html#ErrorHandling">ErrorHandling</a> = <a href="../builtin/index.html#iota">iota</a> <span class="comment">// Return a descriptive error.</span>
  592. <span id="ExitOnError">ExitOnError</span> <span class="comment">// Call os.Exit(2).</span>
  593. <span id="PanicOnError">PanicOnError</span> <span class="comment">// Call panic with a descriptive error.</span>
  594. )</pre>
  595. <p>
  596. These constants cause FlagSet.Parse to behave as described if the parse fails.
  597. </p>
  598. <h2 id="Flag">type <a href="http://localhost:6060/src/flag/flag.go?s=7702:7906#L272">Flag</a></h2>
  599. <pre>type Flag struct {
  600. Name <a href="../builtin/index.html#string">string</a> <span class="comment">// name as it appears on command line</span>
  601. Usage <a href="../builtin/index.html#string">string</a> <span class="comment">// help message</span>
  602. Value <a href="index.html#Value">Value</a> <span class="comment">// value as set</span>
  603. DefValue <a href="../builtin/index.html#string">string</a> <span class="comment">// default value (as text); for usage message</span>
  604. }</pre>
  605. <p>
  606. A Flag represents the state of a flag.
  607. </p>
  608. <h3 id="Lookup">func <a href="http://localhost:6060/src/flag/flag.go?s=9637:9667#L343">Lookup</a></h3>
  609. <pre>func Lookup(name <a href="../builtin/index.html#string">string</a>) *<a href="index.html#Flag">Flag</a></pre>
  610. <p>
  611. Lookup returns the Flag structure of the named command-line flag,
  612. returning nil if none exists.
  613. </p>
  614. <h2 id="FlagSet">type <a href="http://localhost:6060/src/flag/flag.go?s=7193:7658#L256">FlagSet</a></h2>
  615. <pre>type FlagSet struct {
  616. <span class="comment">// Usage is the function called when an error occurs while parsing flags.</span>
  617. <span class="comment">// The field is a function (not a method) that may be changed to point to</span>
  618. <span class="comment">// a custom error handler.</span>
  619. Usage func()
  620. <span class="comment">// contains filtered or unexported fields</span>
  621. }</pre>
  622. <p>
  623. A FlagSet represents a set of defined flags. The zero value of a FlagSet
  624. has no name and has ContinueOnError error handling.
  625. </p>
  626. <h3 id="NewFlagSet">func <a href="http://localhost:6060/src/flag/flag.go?s=31247:31313#L933">NewFlagSet</a></h3>
  627. <pre>func NewFlagSet(name <a href="../builtin/index.html#string">string</a>, errorHandling <a href="index.html#ErrorHandling">ErrorHandling</a>) *<a href="index.html#FlagSet">FlagSet</a></pre>
  628. <p>
  629. NewFlagSet returns a new, empty flag set with the specified name and
  630. error handling property.
  631. </p>
  632. <h3 id="FlagSet.Arg">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=14978:15013#L510">Arg</a></h3>
  633. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Arg(i <a href="../builtin/index.html#int">int</a>) <a href="../builtin/index.html#string">string</a></pre>
  634. <p>
  635. Arg returns the i&#39;th argument. Arg(0) is the first remaining argument
  636. after flags have been processed. Arg returns an empty string if the
  637. requested element does not exist.
  638. </p>
  639. <h3 id="FlagSet.Args">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15633:15666#L531">Args</a></h3>
  640. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Args() []<a href="../builtin/index.html#string">string</a></pre>
  641. <p>
  642. Args returns the non-flag arguments.
  643. </p>
  644. <h3 id="FlagSet.Bool">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=16543:16610#L550">Bool</a></h3>
  645. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Bool(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#bool">bool</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#bool">bool</a></pre>
  646. <p>
  647. Bool defines a bool flag with specified name, default value, and usage string.
  648. The return value is the address of a bool variable that stores the value of the flag.
  649. </p>
  650. <h3 id="FlagSet.BoolVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15959:16032#L538">BoolVar</a></h3>
  651. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) BoolVar(p *<a href="../builtin/index.html#bool">bool</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#bool">bool</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  652. <p>
  653. BoolVar defines a bool flag with specified name, default value, and usage string.
  654. The argument p points to a bool variable in which to store the value of the flag.
  655. </p>
  656. <h3 id="FlagSet.Duration">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=25210:25299#L735">Duration</a></h3>
  657. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Duration(name <a href="../builtin/index.html#string">string</a>, value <a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a></pre>
  658. <p>
  659. Duration defines a time.Duration flag with specified name, default value, and usage string.
  660. The return value is the address of a time.Duration variable that stores the value of the flag.
  661. The flag accepts a value acceptable to time.ParseDuration.
  662. </p>
  663. <h3 id="FlagSet.DurationVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=24406:24501#L721">DurationVar</a></h3>
  664. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) DurationVar(p *<a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../time/index.html">time</a>.<a href="../time/index.html#Duration">Duration</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  665. <p>
  666. DurationVar defines a time.Duration flag with specified name, default value, and usage string.
  667. The argument p points to a time.Duration variable in which to store the value of the flag.
  668. The flag accepts a value acceptable to time.ParseDuration.
  669. </p>
  670. <h3 id="FlagSet.Float64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=23707:23783#L706">Float64</a></h3>
  671. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Float64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#float64">float64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#float64">float64</a></pre>
  672. <p>
  673. Float64 defines a float64 flag with specified name, default value, and usage string.
  674. The return value is the address of a float64 variable that stores the value of the flag.
  675. </p>
  676. <h3 id="FlagSet.Float64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=23081:23163#L694">Float64Var</a></h3>
  677. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Float64Var(p *<a href="../builtin/index.html#float64">float64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#float64">float64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  678. <p>
  679. Float64Var defines a float64 flag with specified name, default value, and usage string.
  680. The argument p points to a float64 variable in which to store the value of the flag.
  681. </p>
  682. <h3 id="FlagSet.Init">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=31570:31634#L944">Init</a></h3>
  683. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Init(name <a href="../builtin/index.html#string">string</a>, errorHandling <a href="index.html#ErrorHandling">ErrorHandling</a>)</pre>
  684. <p>
  685. Init sets the name and error handling property for a flag set.
  686. By default, the zero FlagSet uses an empty name and the
  687. ContinueOnError error handling policy.
  688. </p>
  689. <h3 id="FlagSet.Int">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=17695:17759#L576">Int</a></h3>
  690. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Int(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int">int</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#int">int</a></pre>
  691. <p>
  692. Int defines an int flag with specified name, default value, and usage string.
  693. The return value is the address of an int variable that stores the value of the flag.
  694. </p>
  695. <h3 id="FlagSet.Int64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=18871:18941#L602">Int64</a></h3>
  696. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Int64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int64">int64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#int64">int64</a></pre>
  697. <p>
  698. Int64 defines an int64 flag with specified name, default value, and usage string.
  699. The return value is the address of an int64 variable that stores the value of the flag.
  700. </p>
  701. <h3 id="FlagSet.Int64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=18269:18345#L590">Int64Var</a></h3>
  702. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Int64Var(p *<a href="../builtin/index.html#int64">int64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int64">int64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  703. <p>
  704. Int64Var defines an int64 flag with specified name, default value, and usage string.
  705. The argument p points to an int64 variable in which to store the value of the flag.
  706. </p>
  707. <h3 id="FlagSet.IntVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=17121:17191#L564">IntVar</a></h3>
  708. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) IntVar(p *<a href="../builtin/index.html#int">int</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#int">int</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  709. <p>
  710. IntVar defines an int flag with specified name, default value, and usage string.
  711. The argument p points to an int variable in which to store the value of the flag.
  712. </p>
  713. <h3 id="FlagSet.Lookup">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9463:9506#L337">Lookup</a></h3>
  714. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Lookup(name <a href="../builtin/index.html#string">string</a>) *<a href="index.html#Flag">Flag</a></pre>
  715. <p>
  716. Lookup returns the Flag structure of the named flag, returning nil if none exists.
  717. </p>
  718. <h3 id="FlagSet.NArg">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15412:15440#L525">NArg</a></h3>
  719. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) NArg() <a href="../builtin/index.html#int">int</a></pre>
  720. <p>
  721. NArg is the number of arguments remaining after flags have been processed.
  722. </p>
  723. <h3 id="FlagSet.NFlag">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=14617:14646#L502">NFlag</a></h3>
  724. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) NFlag() <a href="../builtin/index.html#int">int</a></pre>
  725. <p>
  726. NFlag returns the number of flags that have been set.
  727. </p>
  728. <h3 id="FlagSet.Parse">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=30088:30137#L886">Parse</a></h3>
  729. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Parse(arguments []<a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a></pre>
  730. <p>
  731. Parse parses flag definitions from the argument list, which should not
  732. include the command name. Must be called after all flags in the FlagSet
  733. are defined and before flags are accessed by the program.
  734. The return value will be ErrHelp if -help or -h were set but not defined.
  735. </p>
  736. <h3 id="FlagSet.Parsed">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=30478:30509#L910">Parsed</a></h3>
  737. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Parsed() <a href="../builtin/index.html#bool">bool</a></pre>
  738. <p>
  739. Parsed reports whether f.Parse has been called.
  740. </p>
  741. <h3 id="FlagSet.PrintDefaults">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=11761:11794#L425">PrintDefaults</a></h3>
  742. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) PrintDefaults()</pre>
  743. <p>
  744. PrintDefaults prints to standard error the default values of all
  745. defined command-line flags in the set. See the documentation for
  746. the global function PrintDefaults for more information.
  747. </p>
  748. <h3 id="FlagSet.Set">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9747:9794#L348">Set</a></h3>
  749. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Set(name, value <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a></pre>
  750. <p>
  751. Set sets the value of the named flag.
  752. </p>
  753. <h3 id="FlagSet.SetOutput">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=8468:8513#L304">SetOutput</a></h3>
  754. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) SetOutput(output <a href="../io/index.html">io</a>.<a href="../io/index.html#Writer">Writer</a>)</pre>
  755. <p>
  756. SetOutput sets the destination for usage and error messages.
  757. If output is nil, os.Stderr is used.
  758. </p>
  759. <h3 id="FlagSet.String">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=22469:22542#L680">String</a></h3>
  760. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) String(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#string">string</a></pre>
  761. <p>
  762. String defines a string flag with specified name, default value, and usage string.
  763. The return value is the address of a string variable that stores the value of the flag.
  764. </p>
  765. <h3 id="FlagSet.StringVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=21857:21936#L668">StringVar</a></h3>
  766. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) StringVar(p *<a href="../builtin/index.html#string">string</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  767. <p>
  768. StringVar defines a string flag with specified name, default value, and usage string.
  769. The argument p points to a string variable in which to store the value of the flag.
  770. </p>
  771. <h3 id="FlagSet.Uint">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=20050:20117#L628">Uint</a></h3>
  772. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Uint(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint">uint</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#uint">uint</a></pre>
  773. <p>
  774. Uint defines a uint flag with specified name, default value, and usage string.
  775. The return value is the address of a uint variable that stores the value of the flag.
  776. </p>
  777. <h3 id="FlagSet.Uint64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=21248:21321#L654">Uint64</a></h3>
  778. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Uint64(name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint64">uint64</a>, usage <a href="../builtin/index.html#string">string</a>) *<a href="../builtin/index.html#uint64">uint64</a></pre>
  779. <p>
  780. Uint64 defines a uint64 flag with specified name, default value, and usage string.
  781. The return value is the address of a uint64 variable that stores the value of the flag.
  782. </p>
  783. <h3 id="FlagSet.Uint64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=20636:20715#L642">Uint64Var</a></h3>
  784. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Uint64Var(p *<a href="../builtin/index.html#uint64">uint64</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint64">uint64</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  785. <p>
  786. Uint64Var defines a uint64 flag with specified name, default value, and usage string.
  787. The argument p points to a uint64 variable in which to store the value of the flag.
  788. </p>
  789. <h3 id="FlagSet.UintVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=19464:19537#L616">UintVar</a></h3>
  790. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) UintVar(p *<a href="../builtin/index.html#uint">uint</a>, name <a href="../builtin/index.html#string">string</a>, value <a href="../builtin/index.html#uint">uint</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  791. <p>
  792. UintVar defines a uint flag with specified name, default value, and usage string.
  793. The argument p points to a uint variable in which to store the value of the flag.
  794. </p>
  795. <h3 id="FlagSet.Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=26215:26276#L754">Var</a></h3>
  796. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Var(value <a href="index.html#Value">Value</a>, name <a href="../builtin/index.html#string">string</a>, usage <a href="../builtin/index.html#string">string</a>)</pre>
  797. <p>
  798. Var defines a flag with the specified name and usage string. The type and
  799. value of the flag are represented by the first argument, of type Value, which
  800. typically holds a user-defined implementation of Value. For instance, the
  801. caller could create a flag that turns a comma-separated string into a slice
  802. of strings by giving the slice the methods of Value; in particular, Set would
  803. decompose the comma-separated string into the slice.
  804. </p>
  805. <h3 id="FlagSet.Visit">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9082:9121#L324">Visit</a></h3>
  806. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Visit(fn func(*<a href="index.html#Flag">Flag</a>))</pre>
  807. <p>
  808. Visit visits the flags in lexicographical order, calling fn for each.
  809. It visits only those flags that have been set.
  810. </p>
  811. <h3 id="FlagSet.VisitAll">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=8658:8700#L310">VisitAll</a></h3>
  812. <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) VisitAll(fn func(*<a href="index.html#Flag">Flag</a>))</pre>
  813. <p>
  814. VisitAll visits the flags in lexicographical order, calling fn for each.
  815. It visits all flags, even those not set.
  816. </p>
  817. <h2 id="Getter">type <a href="http://localhost:6060/src/flag/flag.go?s=6615:6666#L239">Getter</a></h2>
  818. <pre>type Getter interface {
  819. <a href="index.html#Value">Value</a>
  820. Get() interface{}
  821. }</pre>
  822. <p>
  823. Getter is an interface that allows the contents of a Value to be retrieved.
  824. It wraps the Value interface, rather than being part of it, because it
  825. appeared after Go 1 and its compatibility rules. All Value types provided
  826. by this package satisfy the Getter interface.
  827. </p>
  828. <h2 id="Value">type <a href="http://localhost:6060/src/flag/flag.go?s=6274:6334#L230">Value</a></h2>
  829. <pre>type Value interface {
  830. String() <a href="../builtin/index.html#string">string</a>
  831. Set(<a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a>
  832. }</pre>
  833. <p>
  834. Value is the interface to the dynamic value stored in a flag.
  835. (The default value is represented as a string.)
  836. </p>
  837. <p>
  838. If a Value has an IsBoolFlag() bool method returning true,
  839. the command-line parser makes -name equivalent to -name=true
  840. rather than using the next command-line argument.
  841. </p>
  842. <p>
  843. Set is called once, in command line order, for each flag present.
  844. </p>
  845. <div id="footer">
  846. Build version go1.6.<br>
  847. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  848. the content of this page is licensed under the
  849. Creative Commons Attribution 3.0 License,
  850. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  851. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  852. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  853. </div>
  854. </div><!-- .container -->
  855. </div><!-- #page -->
  856. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  857. <script type="text/javascript" src="../../lib/godoc/jquery.js"></script>
  858. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script>
  859. <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
  860. <script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
  861. </body>
  862. </html>