...

Source file src/github.com/spf13/pflag/example_test.go

Documentation: github.com/spf13/pflag

     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  
     5  package pflag_test
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/spf13/pflag"
    11  )
    12  
    13  func ExampleShorthandLookup() {
    14  	name := "verbose"
    15  	short := name[:1]
    16  
    17  	pflag.BoolP(name, short, false, "verbose output")
    18  
    19  	// len(short) must be == 1
    20  	flag := pflag.ShorthandLookup(short)
    21  
    22  	fmt.Println(flag.Name)
    23  }
    24  
    25  func ExampleFlagSet_ShorthandLookup() {
    26  	name := "verbose"
    27  	short := name[:1]
    28  
    29  	fs := pflag.NewFlagSet("Example", pflag.ContinueOnError)
    30  	fs.BoolP(name, short, false, "verbose output")
    31  
    32  	// len(short) must be == 1
    33  	flag := fs.ShorthandLookup(short)
    34  
    35  	fmt.Println(flag.Name)
    36  }
    37  

View as plain text