summaryrefslogtreecommitdiff
path: root/libgo/go/flag/flag.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/flag/flag.go')
-rw-r--r--libgo/go/flag/flag.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/libgo/go/flag/flag.go b/libgo/go/flag/flag.go
index 6a516175245..286bba68739 100644
--- a/libgo/go/flag/flag.go
+++ b/libgo/go/flag/flag.go
@@ -9,9 +9,9 @@
Define flags using flag.String(), Bool(), Int(), etc.
- This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
+ This declares an integer flag, -n, stored in the pointer nFlag, with type *int:
import "flag"
- var ip = flag.Int("flagname", 1234, "help message for flagname")
+ var nFlag = flag.Int("n", 1234, "help message for flag n")
If you like, you can bind the flag to a variable using the Var() functions.
var flagvar int
func init() {
@@ -308,7 +308,7 @@ type ErrorHandling int
// These constants cause FlagSet.Parse to behave as described if the parse fails.
const (
ContinueOnError ErrorHandling = iota // Return a descriptive error.
- ExitOnError // Call os.Exit(2).
+ ExitOnError // Call os.Exit(2) or for -h/-help Exit(0).
PanicOnError // Call panic with a descriptive error.
)
@@ -331,7 +331,7 @@ type FlagSet struct {
formal map[string]*Flag
args []string // arguments after flags
errorHandling ErrorHandling
- output io.Writer // nil means stderr; use out() accessor
+ output io.Writer // nil means stderr; use Output() accessor
}
// A Flag represents the state of a flag.
@@ -979,6 +979,9 @@ func (f *FlagSet) Parse(arguments []string) error {
case ContinueOnError:
return err
case ExitOnError:
+ if err == ErrHelp {
+ os.Exit(0)
+ }
os.Exit(2)
case PanicOnError:
panic(err)