mirror of
https://github.com/golang/go
synced 2024-10-04 14:31:21 -06:00
f4fe688b09
A FlagSet is an independent set of flags that may be used, for example, to provide flag processing for subcommands in a CLI. The standard, os.Args-derived set of flags is a global but non-exported FlagSet and the standard functions are wrappers for methods of that FlagSet. Allow the programmer to control whether the program exits if there is a parse error. For the default set, the behavior remains to exit on error. The handling of Usage is odd due to backward compatibility. R=golang-dev, bradfitz, r, bradfitz CC=golang-dev https://golang.org/cl/4517092
23 lines
641 B
Go
23 lines
641 B
Go
// Copyright 2010 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.
|
|
|
|
package flag
|
|
|
|
import "os"
|
|
|
|
// Additional routines compiled into the package only during testing.
|
|
|
|
// ResetForTesting clears all flag state and sets the usage function as directed.
|
|
// After calling ResetForTesting, parse errors in flag handling will not
|
|
// exit the program.
|
|
func ResetForTesting(usage func()) {
|
|
commandLine = NewFlagSet(os.Args[0], ContinueOnError)
|
|
Usage = usage
|
|
}
|
|
|
|
// CommandLine returns the default FlagSet.
|
|
func CommandLine() *FlagSet {
|
|
return commandLine
|
|
}
|