example_test.go 719 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2012 The Go Authors. 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.
  4. package pflag_test
  5. import (
  6. "fmt"
  7. "github.com/spf13/pflag"
  8. )
  9. func ExampleShorthandLookup() {
  10. name := "verbose"
  11. short := name[:1]
  12. pflag.BoolP(name, short, false, "verbose output")
  13. // len(short) must be == 1
  14. flag := pflag.ShorthandLookup(short)
  15. fmt.Println(flag.Name)
  16. }
  17. func ExampleFlagSet_ShorthandLookup() {
  18. name := "verbose"
  19. short := name[:1]
  20. fs := pflag.NewFlagSet("Example", pflag.ContinueOnError)
  21. fs.BoolP(name, short, false, "verbose output")
  22. // len(short) must be == 1
  23. flag := fs.ShorthandLookup(short)
  24. fmt.Println(flag.Name)
  25. }