aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example_test.go17
1 files changed, 3 insertions, 14 deletions
diff --git a/example_test.go b/example_test.go
index fc3eb6c..f73e7cc 100644
--- a/example_test.go
+++ b/example_test.go
@@ -7,7 +7,7 @@ package pflag_test
import (
"errors"
- "flag"
+ flag "pflag"
"fmt"
"strings"
"time"
@@ -16,19 +16,8 @@ import (
// Example 1: A single string flag called "species" with default value "gopher".
var species = flag.String("species", "gopher", "the species we are studying")
-// Example 2: Two flags sharing a variable, so we can have a shorthand.
-// The order of initialization is undefined, so make sure both use the
-// same default value. They must be set up with an init function.
-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)")
-}
+// Example 2: A flag with a shorthand letter.
+var gopherType = flag.StringP("gopher_type", "g", "pocket", "the variety of gopher")
// Example 3: A user-defined flag type, a slice of durations.
type interval []time.Duration