tags:

views:

177

answers:

2

Can anyone explain flags in Go?

flag.Parse()
var omitNewline = flag.Bool("n", false, "don't print final newline")
+2  A: 

flag is used to parse command line arguments. If you pass "-n" as a command line argument, omitNewLine will be set to true. It's explained a bit farther in the tutorial :

Having imported the flag package, line 12 creates a global variable to hold the value of echo's -n flag. The variable omitNewline has type *bool, pointer to bool.

Thomas Levesque
I'd actually like to know what the 3 arguments are
Casebash
+2  A: 

See http://golang.org/pkg/flag/ for a full description.

The arguments for flag.Bool are (name string, value bool, usage string)

name is the argument to look for, value is the default value and usage describes the flag's purpose for a -help argument or similar, and is displayed with flag.Usage().

Scott Wales