Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
100644 51 lines (49 sloc) 2.507 kb
462a160 Added license
Jesse van den Kieboom authored
1 // Copyright 2012 Jesse van den Kieboom. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
cfc3da2 Added documentation
Jesse van den Kieboom authored
5 // Package flags provides an extensive command line option parser.
6 // The flags package is similar in functionality to the go builtin flag package
7 // but provides more options and uses reflection to provide a convenient and
8 // succinct way of specifying command line options.
9 //
10 // Supported features:
11 // Options with short names (-v)
12 // Options with long names (--verbose)
13 // Options with and without arguments (bool v.s. other type)
14 // Options with optional arguments and default values
15 // Multiple option groups each containing a set of options
16 // Generate and print well-formatted help message
17 // Passing remaining command line arguments after -- (optional)
18 // Ignoring unknown command line options (optional)
19 // Supports -I/usr/include -I=/usr/include -I /usr/include option argument specification
20 // Supports multiple short options -aux
21 // Supports all primitive go types (string, int{8..64}, uint{8..64}, float)
22 // Supports same option multiple times (can store in slice or last option counts)
48930a9 Updated documentation to include maps and function callbacks
Jesse van den Kieboom authored
23 // Supports maps
24 // Supports function callbacks
cfc3da2 Added documentation
Jesse van den Kieboom authored
25 //
26 // The flags package uses structs, reflection and struct field tags
27 // to allow users to specify command line options. This results in very simple
28 // and consise specification of your application options. For example:
29 //
30 // type Options struct {
e139cd3 Added missing ` in doc
Jesse van den Kieboom authored
31 // Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug information"`
cfc3da2 Added documentation
Jesse van den Kieboom authored
32 // }
33 //
34 // This specifies one option with a short name -v and a long name --verbose.
35 // When either -v or --verbose is found on the command line, a 'true' value
36 // will be appended to the Verbose field. e.g. when specifying -vvv, the
37 // resulting value of Verbose will be {[true, true, true]}.
38 //
39 // Available field tags:
40 // short: the short name of the option (single character)
41 // long: the long name of the option
42 // description: the description of the option (optional)
43 // optional: whether an argument of the option is optional (optional)
44 // default: the default argument value if the option occurs without
45 // an argument (optional)
e37ecb2 Added documentation for 'base' tag
Jesse van den Kieboom authored
46 // base: a base used to convert strings to integer values (optional)
cfc3da2 Added documentation
Jesse van den Kieboom authored
47 //
48 // Either short: or long: must be specified to make the field eligible as an
49 // option.
c3d1968 Initial import
Jesse van den Kieboom authored
50 package flags
Something went wrong with that request. Please try again.