|
|
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="theme-color" content="#375EAB">
<title>flag - The Go Programming Language</title>
<link type="text/css" rel="stylesheet" href="../../lib/godoc/style.css">
<link rel="stylesheet" href="../../lib/godoc/jquery.treeview.css"> <script type="text/javascript">window.initFuncs = [];</script> </head> <body>
<div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;"> ... </div><!-- #lowframe -->
<div id="topbar" class="wide"><div class="container"> <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div> <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div> <a href="index.html#" id="menu-button"><span id="menu-button-arrow">▽</span></a> <form method="GET" action="http://localhost:6060/search"> <div id="menu"> <a href="http://localhost:6060/doc/">Documents</a> <a href="http://localhost:6060/pkg/">Packages</a> <a href="http://localhost:6060/project/">The Project</a> <a href="http://localhost:6060/help/">Help</a> <a href="http://localhost:6060/blog/">Blog</a>
<input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search"> </div> </form>
</div></div>
<div id="page" class="wide"> <div class="container">
<h1>Package flag</h1>
<div id="nav"></div>
<!--
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> <!--
Note: Static (i.e., not template-generated) href and id attributes start with "pkg-" to make it impossible for them to conflict with generated attributes (some of which correspond to Go identifiers). -->
<script type='text/javascript'> document.ANALYSIS_DATA = null; document.CALLGRAPH = null; </script>
<div id="short-nav"> <dl> <dd><code>import "flag"</code></dd> </dl> <dl> <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd> <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd> <dd><a href="index.html#pkg-examples" class="examplesLink">Examples</a></dd> </dl> </div> <!-- The package's Name is printed as title by the top-level template --> <div id="pkg-overview" class="toggleVisible"> <div class="collapsed"> <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2> </div> <div class="expanded"> <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2> <p> Package flag implements command-line flag parsing. </p> <p> Usage: </p> <p> Define flags using flag.String(), Bool(), Int(), etc. </p> <p> This declares an integer flag, -flagname, stored in the pointer ip, with type *int. </p> <pre>import "flag" var ip = flag.Int("flagname", 1234, "help message for flagname") </pre> <p> If you like, you can bind the flag to a variable using the Var() functions. </p> <pre>var flagvar int func init() { flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname") } </pre> <p> Or you can create custom flags that satisfy the Value interface (with pointer receivers) and couple them to flag parsing by </p> <pre>flag.Var(&flagVal, "name", "help message for flagname") </pre> <p> For such flags, the default value is just the initial value of the variable. </p> <p> After all flags are defined, call </p> <pre>flag.Parse() </pre> <p> to parse the command line into the defined flags. </p> <p> Flags may then be used directly. If you're using the flags themselves, they are all pointers; if you bind to variables, they're values. </p> <pre>fmt.Println("ip has value ", *ip) fmt.Println("flagvar has value ", flagvar) </pre> <p> After parsing, the arguments following the flags are available as the slice flag.Args() or individually as flag.Arg(i). The arguments are indexed from 0 through flag.NArg()-1. </p> <p> Command line flag syntax: </p> <pre>-flag -flag=x -flag x // non-boolean flags only </pre> <p> One or two minus signs may be used; they are equivalent. The last form is not permitted for boolean flags because the meaning of the command </p> <pre>cmd -x * </pre> <p> will change if there is a file called 0, false, etc. You must use the -flag=false form to turn off a boolean flag. </p> <p> Flag parsing stops just before the first non-flag argument ("-" is a non-flag argument) or after the terminator "--". </p> <p> Integer flags accept 1234, 0664, 0x1234 and may be negative. Boolean flags may be: </p> <pre>1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False </pre> <p> Duration flags accept any input valid for time.ParseDuration. </p> <p> The default set of command-line flags is controlled by top-level functions. The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface. The methods of FlagSet are analogous to the top-level functions for the command-line flag set. </p>
</div> </div> <div id="example_" class="toggle"> <div class="collapsed"> <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p> </div> <div class="expanded"> <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p> <p>Code:</p> <pre class="code"><span class="comment">// These examples demonstrate more intricate uses of the flag package.</span> package flag_test
import ( "errors" "flag" "fmt" "strings" "time" )
<span class="comment">// Example 1: A single string flag called "species" with default value "gopher".</span> var species = flag.String("species", "gopher", "the species we are studying")
<span class="comment">// Example 2: Two flags sharing a variable, so we can have a shorthand.</span> <span class="comment">// The order of initialization is undefined, so make sure both use the</span> <span class="comment">// same default value. They must be set up with an init function.</span> var gopherType string
func init() { const ( defaultGopher = "pocket" usage = "the variety of gopher" ) flag.StringVar(&gopherType, "gopher_type", defaultGopher, usage) flag.StringVar(&gopherType, "g", defaultGopher, usage+" (shorthand)") }
<span class="comment">// Example 3: A user-defined flag type, a slice of durations.</span> type interval []time.Duration
<span class="comment">// String is the method to format the flag's value, part of the flag.Value interface.</span> <span class="comment">// The String method's output will be used in diagnostics.</span> func (i *interval) String() string { return fmt.Sprint(*i) }
<span class="comment">// Set is the method to set the flag value, part of the flag.Value interface.</span> <span class="comment">// Set's argument is a string to be parsed to set the flag.</span> <span class="comment">// It's a comma-separated list, so we split it.</span> func (i *interval) Set(value string) error { <span class="comment">// If we wanted to allow the flag to be set multiple times,</span> <span class="comment">// accumulating values, we would delete this if statement.</span> <span class="comment">// That would permit usages such as</span> <span class="comment">// -deltaT 10s -deltaT 15s</span> <span class="comment">// and other combinations.</span> if len(*i) > 0 { return errors.New("interval flag already set") } for _, dt := range strings.Split(value, ",") { duration, err := time.ParseDuration(dt) if err != nil { return err } *i = append(*i, duration) } return nil }
<span class="comment">// Define a flag to accumulate durations. Because it has a special type,</span> <span class="comment">// we need to use the Var function and therefore create the flag during</span> <span class="comment">// init.</span>
var intervalFlag interval
func init() { <span class="comment">// Tie the command-line flag to the intervalFlag variable and</span> <span class="comment">// set a usage message.</span> flag.Var(&intervalFlag, "deltaT", "comma-separated list of intervals to use between events") }
func Example() { <span class="comment">// All the interesting pieces are with the variables declared above, but</span> <span class="comment">// to enable the flag package to see the flags defined there, one must</span> <span class="comment">// execute, typically at the start of main (not init!):</span> <span class="comment">// flag.Parse()</span> <span class="comment">// We don't run it here because this is not a main function and</span> <span class="comment">// the testing suite has already parsed the flags.</span> } </pre> </div> </div>
<div id="pkg-index" class="toggleVisible"> <div class="collapsed"> <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2> </div> <div class="expanded"> <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<!-- Table of contents for API; must be named manual-nav to turn off auto nav. --> <div id="manual-nav"> <dl> <dd><a href="index.html#pkg-variables">Variables</a></dd> <dd><a href="index.html#Arg">func Arg(i int) string</a></dd> <dd><a href="index.html#Args">func Args() []string</a></dd> <dd><a href="index.html#Bool">func Bool(name string, value bool, usage string) *bool</a></dd> <dd><a href="index.html#BoolVar">func BoolVar(p *bool, name string, value bool, usage string)</a></dd> <dd><a href="index.html#Duration">func Duration(name string, value time.Duration, usage string) *time.Duration</a></dd> <dd><a href="index.html#DurationVar">func DurationVar(p *time.Duration, name string, value time.Duration, usage string)</a></dd> <dd><a href="index.html#Float64">func Float64(name string, value float64, usage string) *float64</a></dd> <dd><a href="index.html#Float64Var">func Float64Var(p *float64, name string, value float64, usage string)</a></dd> <dd><a href="index.html#Int">func Int(name string, value int, usage string) *int</a></dd> <dd><a href="index.html#Int64">func Int64(name string, value int64, usage string) *int64</a></dd> <dd><a href="index.html#Int64Var">func Int64Var(p *int64, name string, value int64, usage string)</a></dd> <dd><a href="index.html#IntVar">func IntVar(p *int, name string, value int, usage string)</a></dd> <dd><a href="index.html#NArg">func NArg() int</a></dd> <dd><a href="index.html#NFlag">func NFlag() int</a></dd> <dd><a href="index.html#Parse">func Parse()</a></dd> <dd><a href="index.html#Parsed">func Parsed() bool</a></dd> <dd><a href="index.html#PrintDefaults">func PrintDefaults()</a></dd> <dd><a href="index.html#Set">func Set(name, value string) error</a></dd> <dd><a href="index.html#String">func String(name string, value string, usage string) *string</a></dd> <dd><a href="index.html#StringVar">func StringVar(p *string, name string, value string, usage string)</a></dd> <dd><a href="index.html#Uint">func Uint(name string, value uint, usage string) *uint</a></dd> <dd><a href="index.html#Uint64">func Uint64(name string, value uint64, usage string) *uint64</a></dd> <dd><a href="index.html#Uint64Var">func Uint64Var(p *uint64, name string, value uint64, usage string)</a></dd> <dd><a href="index.html#UintVar">func UintVar(p *uint, name string, value uint, usage string)</a></dd> <dd><a href="index.html#UnquoteUsage">func UnquoteUsage(flag *Flag) (name string, usage string)</a></dd> <dd><a href="index.html#Var">func Var(value Value, name string, usage string)</a></dd> <dd><a href="index.html#Visit">func Visit(fn func(*Flag))</a></dd> <dd><a href="index.html#VisitAll">func VisitAll(fn func(*Flag))</a></dd> <dd><a href="index.html#ErrorHandling">type ErrorHandling</a></dd> <dd><a href="index.html#Flag">type Flag</a></dd> <dd> <a href="index.html#Lookup">func Lookup(name string) *Flag</a></dd> <dd><a href="index.html#FlagSet">type FlagSet</a></dd> <dd> <a href="index.html#NewFlagSet">func NewFlagSet(name string, errorHandling ErrorHandling) *FlagSet</a></dd> <dd> <a href="index.html#FlagSet.Arg">func (f *FlagSet) Arg(i int) string</a></dd> <dd> <a href="index.html#FlagSet.Args">func (f *FlagSet) Args() []string</a></dd> <dd> <a href="index.html#FlagSet.Bool">func (f *FlagSet) Bool(name string, value bool, usage string) *bool</a></dd> <dd> <a href="index.html#FlagSet.BoolVar">func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Duration">func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration</a></dd> <dd> <a href="index.html#FlagSet.DurationVar">func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Float64">func (f *FlagSet) Float64(name string, value float64, usage string) *float64</a></dd> <dd> <a href="index.html#FlagSet.Float64Var">func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Init">func (f *FlagSet) Init(name string, errorHandling ErrorHandling)</a></dd> <dd> <a href="index.html#FlagSet.Int">func (f *FlagSet) Int(name string, value int, usage string) *int</a></dd> <dd> <a href="index.html#FlagSet.Int64">func (f *FlagSet) Int64(name string, value int64, usage string) *int64</a></dd> <dd> <a href="index.html#FlagSet.Int64Var">func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string)</a></dd> <dd> <a href="index.html#FlagSet.IntVar">func (f *FlagSet) IntVar(p *int, name string, value int, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Lookup">func (f *FlagSet) Lookup(name string) *Flag</a></dd> <dd> <a href="index.html#FlagSet.NArg">func (f *FlagSet) NArg() int</a></dd> <dd> <a href="index.html#FlagSet.NFlag">func (f *FlagSet) NFlag() int</a></dd> <dd> <a href="index.html#FlagSet.Parse">func (f *FlagSet) Parse(arguments []string) error</a></dd> <dd> <a href="index.html#FlagSet.Parsed">func (f *FlagSet) Parsed() bool</a></dd> <dd> <a href="index.html#FlagSet.PrintDefaults">func (f *FlagSet) PrintDefaults()</a></dd> <dd> <a href="index.html#FlagSet.Set">func (f *FlagSet) Set(name, value string) error</a></dd> <dd> <a href="index.html#FlagSet.SetOutput">func (f *FlagSet) SetOutput(output io.Writer)</a></dd> <dd> <a href="index.html#FlagSet.String">func (f *FlagSet) String(name string, value string, usage string) *string</a></dd> <dd> <a href="index.html#FlagSet.StringVar">func (f *FlagSet) StringVar(p *string, name string, value string, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Uint">func (f *FlagSet) Uint(name string, value uint, usage string) *uint</a></dd> <dd> <a href="index.html#FlagSet.Uint64">func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64</a></dd> <dd> <a href="index.html#FlagSet.Uint64Var">func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string)</a></dd> <dd> <a href="index.html#FlagSet.UintVar">func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Var">func (f *FlagSet) Var(value Value, name string, usage string)</a></dd> <dd> <a href="index.html#FlagSet.Visit">func (f *FlagSet) Visit(fn func(*Flag))</a></dd> <dd> <a href="index.html#FlagSet.VisitAll">func (f *FlagSet) VisitAll(fn func(*Flag))</a></dd> <dd><a href="index.html#Getter">type Getter</a></dd> <dd><a href="index.html#Value">type Value</a></dd> </dl> </div><!-- #manual-nav -->
<div id="pkg-examples"> <h4>Examples</h4> <dl> <dd><a class="exampleLink" href="index.html#example_">Package</a></dd> </dl> </div>
<h4>Package files</h4> <p> <span style="font-size:90%"> <a href="http://localhost:6060/src/flag/flag.go">flag.go</a> </span> </p> </div><!-- .expanded --> </div><!-- #pkg-index -->
<div id="pkg-callgraph" class="toggle" style="display: none"> <div class="collapsed"> <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2> </div> <!-- .expanded --> <div class="expanded"> <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2> <p> In the call graph viewer below, each node is a function belonging to this package and its children are the functions it calls—perhaps dynamically. </p> <p> The root nodes are the entry points of the package: functions that may be called from outside the package. There may be non-exported or anonymous functions among them if they are called dynamically from another package. </p> <p> Click a node to visit that function's source code. From there you can visit its callers by clicking its declaring <code>func</code> token. </p> <p> Functions may be omitted if they were determined to be unreachable in the particular programs or tests that were analyzed. </p> <!-- Zero means show all package entry points. --> <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul> </div> </div> <!-- #pkg-callgraph -->
<h2 id="pkg-variables">Variables</h2> <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> <p> CommandLine is the default set of command-line flags, parsed from os.Args. The top-level functions such as BoolVar, Arg, and so on are wrappers for the methods of CommandLine. </p>
<pre>var <span id="ErrHelp">ErrHelp</span> = <a href="../errors/index.html">errors</a>.<a href="../errors/index.html#New">New</a>("flag: help requested")</pre> <p> ErrHelp is the error returned if the -help or -h flag is invoked but no such flag is defined. </p>
<pre>var <span id="Usage">Usage</span> = func() { <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>, "Usage of %s:\n", <a href="../os/index.html">os</a>.<a href="../os/index.html#Args">Args</a>[0]) <a href="index.html#PrintDefaults">PrintDefaults</a>() }</pre> <p> Usage prints to standard error a usage message documenting all defined command-line flags. It is called when an error occurs while parsing flags. The function is a variable that may be changed to point to a custom function. By default it prints a simple header and calls PrintDefaults; for details about the format of the output and how to control it, see the documentation for PrintDefaults. </p>
<h2 id="Arg">func <a href="http://localhost:6060/src/flag/flag.go?s=15279:15301#L520">Arg</a></h2> <pre>func Arg(i <a href="../builtin/index.html#int">int</a>) <a href="../builtin/index.html#string">string</a></pre> <p> Arg returns the i'th command-line argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist. </p>
<h2 id="Args">func <a href="http://localhost:6060/src/flag/flag.go?s=15739:15759#L534">Args</a></h2> <pre>func Args() []<a href="../builtin/index.html#string">string</a></pre> <p> Args returns the non-flag command-line arguments. </p>
<h2 id="Bool">func <a href="http://localhost:6060/src/flag/flag.go?s=16847:16901#L558">Bool</a></h2> <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> <p> Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag. </p>
<h2 id="BoolVar">func <a href="http://localhost:6060/src/flag/flag.go?s=16252:16312#L544">BoolVar</a></h2> <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> <p> BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag. </p>
<h2 id="Duration">func <a href="http://localhost:6060/src/flag/flag.go?s=25633:25709#L744">Duration</a></h2> <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> <p> Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag. The flag accepts a value acceptable to time.ParseDuration. </p>
<h2 id="DurationVar">func <a href="http://localhost:6060/src/flag/flag.go?s=24809:24891#L728">DurationVar</a></h2> <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> <p> DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag. The flag accepts a value acceptable to time.ParseDuration. </p>
<h2 id="Float64">func <a href="http://localhost:6060/src/flag/flag.go?s=24035:24098#L714">Float64</a></h2> <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> <p> Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag. </p>
<h2 id="Float64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=23395:23464#L700">Float64Var</a></h2> <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> <p> Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag. </p>
<h2 id="Int">func <a href="http://localhost:6060/src/flag/flag.go?s=17993:18044#L584">Int</a></h2> <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> <p> Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag. </p>
<h2 id="Int64">func <a href="http://localhost:6060/src/flag/flag.go?s=19185:19242#L610">Int64</a></h2> <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> <p> Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag. </p>
<h2 id="Int64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=18571:18634#L596">Int64Var</a></h2> <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> <p> Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag. </p>
<h2 id="IntVar">func <a href="http://localhost:6060/src/flag/flag.go?s=17409:17466#L570">IntVar</a></h2> <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> <p> IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag. </p>
<h2 id="NArg">func <a href="http://localhost:6060/src/flag/flag.go?s=15543:15558#L528">NArg</a></h2> <pre>func NArg() <a href="../builtin/index.html#int">int</a></pre> <p> NArg is the number of arguments remaining after flags have been processed. </p>
<h2 id="NFlag">func <a href="http://localhost:6060/src/flag/flag.go?s=14743:14759#L505">NFlag</a></h2> <pre>func NFlag() <a href="../builtin/index.html#int">int</a></pre> <p> NFlag returns the number of command-line flags that have been set. </p>
<h2 id="Parse">func <a href="http://localhost:6060/src/flag/flag.go?s=30682:30694#L916">Parse</a></h2> <pre>func Parse()</pre> <p> Parse parses the command-line flags from os.Args[1:]. Must be called after all flags are defined and before flags are accessed by the program. </p>
<h2 id="Parsed">func <a href="http://localhost:6060/src/flag/flag.go?s=30854:30872#L922">Parsed</a></h2> <pre>func Parsed() <a href="../builtin/index.html#bool">bool</a></pre> <p> Parsed reports whether the command-line flags have been parsed. </p>
<h2 id="PrintDefaults">func <a href="http://localhost:6060/src/flag/flag.go?s=13608:13628#L473">PrintDefaults</a></h2> <pre>func PrintDefaults()</pre> <p> PrintDefaults prints, to standard error unless configured otherwise, a usage message showing the default settings of all defined command-line flags. For an integer valued flag x, the default output has the form </p> <pre>-x int usage-message-for-x (default 7) </pre> <p> The usage message will appear on a separate line for anything but a bool flag with a one-byte name. For bool flags, the type is omitted and if the flag name is one byte the usage message appears on the same line. The parenthetical default is omitted if the default is the zero value for the type. The listed type, here int, can be changed by placing a back-quoted name in the flag's usage string; the first such item in the message is taken to be a parameter name to show in the message and the back quotes are stripped from the message when displayed. For instance, given </p> <pre>flag.String("I", "", "search `directory` for include files") </pre> <p> the output will be </p> <pre>-I directory search directory for include files. </pre>
<h2 id="Set">func <a href="http://localhost:6060/src/flag/flag.go?s=10100:10134#L365">Set</a></h2> <pre>func Set(name, value <a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a></pre> <p> Set sets the value of the named command-line flag. </p>
<h2 id="String">func <a href="http://localhost:6060/src/flag/flag.go?s=22789:22849#L688">String</a></h2> <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> <p> String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag. </p>
<h2 id="StringVar">func <a href="http://localhost:6060/src/flag/flag.go?s=22164:22230#L674">StringVar</a></h2> <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> <p> StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag. </p>
<h2 id="Uint">func <a href="http://localhost:6060/src/flag/flag.go?s=20355:20409#L636">Uint</a></h2> <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> <p> Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag. </p>
<h2 id="Uint64">func <a href="http://localhost:6060/src/flag/flag.go?s=21568:21628#L662">Uint64</a></h2> <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> <p> Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag. </p>
<h2 id="Uint64Var">func <a href="http://localhost:6060/src/flag/flag.go?s=20943:21009#L648">Uint64Var</a></h2> <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> <p> Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag. </p>
<h2 id="UintVar">func <a href="http://localhost:6060/src/flag/flag.go?s=19758:19818#L622">UintVar</a></h2> <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> <p> UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag. </p>
<h2 id="UnquoteUsage">func <a href="http://localhost:6060/src/flag/flag.go?s=10786:10843#L388">UnquoteUsage</a></h2> <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> <p> UnquoteUsage extracts a back-quoted name from the usage string for a flag and returns it and the un-quoted usage. Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the flag's value, or the empty string if the flag is boolean. </p>
<h2 id="Var">func <a href="http://localhost:6060/src/flag/flag.go?s=27248:27296#L780">Var</a></h2> <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> <p> Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice. </p>
<h2 id="Visit">func <a href="http://localhost:6060/src/flag/flag.go?s=9322:9348#L332">Visit</a></h2> <pre>func Visit(fn func(*<a href="index.html#Flag">Flag</a>))</pre> <p> Visit visits the command-line flags in lexicographical order, calling fn for each. It visits only those flags that have been set. </p>
<h2 id="VisitAll">func <a href="http://localhost:6060/src/flag/flag.go?s=8898:8927#L318">VisitAll</a></h2> <pre>func VisitAll(fn func(*<a href="index.html#Flag">Flag</a>))</pre> <p> VisitAll visits the command-line flags in lexicographical order, calling fn for each. It visits all flags, even those not set. </p>
<h2 id="ErrorHandling">type <a href="http://localhost:6060/src/flag/flag.go?s=6739:6761#L245">ErrorHandling</a></h2> <pre>type ErrorHandling <a href="../builtin/index.html#int">int</a></pre> <p> ErrorHandling defines how FlagSet.Parse behaves if the parse fails. </p>
<pre>const ( <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> <span id="ExitOnError">ExitOnError</span> <span class="comment">// Call os.Exit(2).</span> <span id="PanicOnError">PanicOnError</span> <span class="comment">// Call panic with a descriptive error.</span> )</pre> <p> These constants cause FlagSet.Parse to behave as described if the parse fails. </p>
<h2 id="Flag">type <a href="http://localhost:6060/src/flag/flag.go?s=7702:7906#L272">Flag</a></h2> <pre>type Flag struct { Name <a href="../builtin/index.html#string">string</a> <span class="comment">// name as it appears on command line</span> Usage <a href="../builtin/index.html#string">string</a> <span class="comment">// help message</span> Value <a href="index.html#Value">Value</a> <span class="comment">// value as set</span> DefValue <a href="../builtin/index.html#string">string</a> <span class="comment">// default value (as text); for usage message</span> }</pre> <p> A Flag represents the state of a flag. </p>
<h3 id="Lookup">func <a href="http://localhost:6060/src/flag/flag.go?s=9637:9667#L343">Lookup</a></h3> <pre>func Lookup(name <a href="../builtin/index.html#string">string</a>) *<a href="index.html#Flag">Flag</a></pre> <p> Lookup returns the Flag structure of the named command-line flag, returning nil if none exists. </p>
<h2 id="FlagSet">type <a href="http://localhost:6060/src/flag/flag.go?s=7193:7658#L256">FlagSet</a></h2> <pre>type FlagSet struct { <span class="comment">// Usage is the function called when an error occurs while parsing flags.</span> <span class="comment">// The field is a function (not a method) that may be changed to point to</span> <span class="comment">// a custom error handler.</span> Usage func() <span class="comment">// contains filtered or unexported fields</span> }</pre> <p> A FlagSet represents a set of defined flags. The zero value of a FlagSet has no name and has ContinueOnError error handling. </p>
<h3 id="NewFlagSet">func <a href="http://localhost:6060/src/flag/flag.go?s=31247:31313#L933">NewFlagSet</a></h3> <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> <p> NewFlagSet returns a new, empty flag set with the specified name and error handling property. </p>
<h3 id="FlagSet.Arg">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=14978:15013#L510">Arg</a></h3> <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> <p> Arg returns the i'th argument. Arg(0) is the first remaining argument after flags have been processed. Arg returns an empty string if the requested element does not exist. </p>
<h3 id="FlagSet.Args">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15633:15666#L531">Args</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Args() []<a href="../builtin/index.html#string">string</a></pre> <p> Args returns the non-flag arguments. </p>
<h3 id="FlagSet.Bool">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=16543:16610#L550">Bool</a></h3> <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> <p> Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag. </p>
<h3 id="FlagSet.BoolVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15959:16032#L538">BoolVar</a></h3> <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> <p> BoolVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag. </p>
<h3 id="FlagSet.Duration">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=25210:25299#L735">Duration</a></h3> <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> <p> Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag. The flag accepts a value acceptable to time.ParseDuration. </p>
<h3 id="FlagSet.DurationVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=24406:24501#L721">DurationVar</a></h3> <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> <p> DurationVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag. The flag accepts a value acceptable to time.ParseDuration. </p>
<h3 id="FlagSet.Float64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=23707:23783#L706">Float64</a></h3> <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> <p> Float64 defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag. </p>
<h3 id="FlagSet.Float64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=23081:23163#L694">Float64Var</a></h3> <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> <p> Float64Var defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag. </p>
<h3 id="FlagSet.Init">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=31570:31634#L944">Init</a></h3> <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> <p> Init sets the name and error handling property for a flag set. By default, the zero FlagSet uses an empty name and the ContinueOnError error handling policy. </p>
<h3 id="FlagSet.Int">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=17695:17759#L576">Int</a></h3> <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> <p> Int defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag. </p>
<h3 id="FlagSet.Int64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=18871:18941#L602">Int64</a></h3> <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> <p> Int64 defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag. </p>
<h3 id="FlagSet.Int64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=18269:18345#L590">Int64Var</a></h3> <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> <p> Int64Var defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag. </p>
<h3 id="FlagSet.IntVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=17121:17191#L564">IntVar</a></h3> <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> <p> IntVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag. </p>
<h3 id="FlagSet.Lookup">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9463:9506#L337">Lookup</a></h3> <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> <p> Lookup returns the Flag structure of the named flag, returning nil if none exists. </p>
<h3 id="FlagSet.NArg">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=15412:15440#L525">NArg</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) NArg() <a href="../builtin/index.html#int">int</a></pre> <p> NArg is the number of arguments remaining after flags have been processed. </p>
<h3 id="FlagSet.NFlag">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=14617:14646#L502">NFlag</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) NFlag() <a href="../builtin/index.html#int">int</a></pre> <p> NFlag returns the number of flags that have been set. </p>
<h3 id="FlagSet.Parse">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=30088:30137#L886">Parse</a></h3> <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> <p> Parse parses flag definitions from the argument list, which should not include the command name. Must be called after all flags in the FlagSet are defined and before flags are accessed by the program. The return value will be ErrHelp if -help or -h were set but not defined. </p>
<h3 id="FlagSet.Parsed">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=30478:30509#L910">Parsed</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Parsed() <a href="../builtin/index.html#bool">bool</a></pre> <p> Parsed reports whether f.Parse has been called. </p>
<h3 id="FlagSet.PrintDefaults">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=11761:11794#L425">PrintDefaults</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) PrintDefaults()</pre> <p> PrintDefaults prints to standard error the default values of all defined command-line flags in the set. See the documentation for the global function PrintDefaults for more information. </p>
<h3 id="FlagSet.Set">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9747:9794#L348">Set</a></h3> <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> <p> Set sets the value of the named flag. </p>
<h3 id="FlagSet.SetOutput">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=8468:8513#L304">SetOutput</a></h3> <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> <p> SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used. </p>
<h3 id="FlagSet.String">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=22469:22542#L680">String</a></h3> <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> <p> String defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag. </p>
<h3 id="FlagSet.StringVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=21857:21936#L668">StringVar</a></h3> <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> <p> StringVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag. </p>
<h3 id="FlagSet.Uint">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=20050:20117#L628">Uint</a></h3> <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> <p> Uint defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag. </p>
<h3 id="FlagSet.Uint64">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=21248:21321#L654">Uint64</a></h3> <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> <p> Uint64 defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag. </p>
<h3 id="FlagSet.Uint64Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=20636:20715#L642">Uint64Var</a></h3> <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> <p> Uint64Var defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag. </p>
<h3 id="FlagSet.UintVar">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=19464:19537#L616">UintVar</a></h3> <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> <p> UintVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag. </p>
<h3 id="FlagSet.Var">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=26215:26276#L754">Var</a></h3> <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> <p> Var defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice. </p>
<h3 id="FlagSet.Visit">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=9082:9121#L324">Visit</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) Visit(fn func(*<a href="index.html#Flag">Flag</a>))</pre> <p> Visit visits the flags in lexicographical order, calling fn for each. It visits only those flags that have been set. </p>
<h3 id="FlagSet.VisitAll">func (*FlagSet) <a href="http://localhost:6060/src/flag/flag.go?s=8658:8700#L310">VisitAll</a></h3> <pre>func (f *<a href="index.html#FlagSet">FlagSet</a>) VisitAll(fn func(*<a href="index.html#Flag">Flag</a>))</pre> <p> VisitAll visits the flags in lexicographical order, calling fn for each. It visits all flags, even those not set. </p>
<h2 id="Getter">type <a href="http://localhost:6060/src/flag/flag.go?s=6615:6666#L239">Getter</a></h2> <pre>type Getter interface { <a href="index.html#Value">Value</a> Get() interface{} }</pre> <p> Getter is an interface that allows the contents of a Value to be retrieved. It wraps the Value interface, rather than being part of it, because it appeared after Go 1 and its compatibility rules. All Value types provided by this package satisfy the Getter interface. </p>
<h2 id="Value">type <a href="http://localhost:6060/src/flag/flag.go?s=6274:6334#L230">Value</a></h2> <pre>type Value interface { String() <a href="../builtin/index.html#string">string</a> Set(<a href="../builtin/index.html#string">string</a>) <a href="../builtin/index.html#error">error</a> }</pre> <p> Value is the interface to the dynamic value stored in a flag. (The default value is represented as a string.) </p> <p> If a Value has an IsBoolFlag() bool method returning true, the command-line parser makes -name equivalent to -name=true rather than using the next command-line argument. </p> <p> Set is called once, in command line order, for each flag present. </p>
<div id="footer"> Build version go1.6.<br> Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br> <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> | <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a> </div>
</div><!-- .container --> </div><!-- #page -->
<!-- TODO(adonovan): load these from <head> using "defer" attribute? --> <script type="text/javascript" src="../../lib/godoc/jquery.js"></script> <script type="text/javascript" src="../../lib/godoc/jquery.treeview.js"></script> <script type="text/javascript" src="../../lib/godoc/jquery.treeview.edit.js"></script>
<script type="text/javascript" src="../../lib/godoc/godocs.js"></script>
</body> </html>
|