Documentation ¶
Index ¶
- Variables
- func Bool(name string, value bool, usage string) *bool
- func BoolVar(p *bool, name string, value bool, usage string)
- func Choice(name string, choices []string, value string, usage string) *string
- func ChoiceVar(p *string, name string, choices []string, value string, usage string)
- func Complete() bool
- func Dir(name string, pattern string, value string, usage string) *string
- func DirVar(p *string, name string, pattern string, value string, usage string)
- func File(name string, pattern string, value string, usage string) *string
- func FileVar(p *string, name string, pattern string, value string, usage string)
- func SetInstallFlags(installName, uninstallName string)
- func StringCompleter(name string, completer Completer, value string, usage string) *string
- func StringCompleterVar(p *string, name string, completer Completer, value string, usage string)
- type CompleteFn
- type Completer
- type FlagSet
- func (f *FlagSet) Bool(name string, value bool, usage string) *bool
- func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string)
- func (f *FlagSet) Choice(name string, choices []string, value string, usage string) *string
- func (f *FlagSet) ChoiceVar(p *string, name string, choices []string, value string, usage string)
- func (f *FlagSet) Complete() bool
- func (f *FlagSet) Dir(name string, pattern string, value string, usage string) *string
- func (f *FlagSet) DirVar(p *string, name string, pattern string, value string, usage string)
- func (f *FlagSet) File(name string, pattern string, value string, usage string) *string
- func (f *FlagSet) FileVar(p *string, name string, pattern string, value string, usage string)
- func (f *FlagSet) SetInstallFlags(installName, uninstallName string)
- func (f *FlagSet) StringCompleter(name string, completer Completer, value string, usage string) *string
- func (f *FlagSet) StringCompleterVar(p *string, name string, completer Completer, value string, usage string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( Parse = gflag.Parse Parsed = gflag.Parsed String = gflag.String StringVar = gflag.StringVar Int = gflag.Int IntVar = gflag.IntVar Int64 = gflag.Int64 Int64Var = gflag.Int64Var Float64 = gflag.Float64 Float64Var = gflag.Float64Var DurationVar = gflag.DurationVar UintVar = gflag.UintVar NArg = gflag.NArg Args = gflag.Args )
Copy functions from standard library
var CommandLine = &FlagSet{gflag.CommandLine}
CommandLine is a copy of CommandLine variable from flag standard library
Functions ¶
func Bool ¶
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func BoolVar ¶
BoolVar defines a bool flag with specified name, default value, and usage string. The argument s points to a bool variable in which to store the value of the flag.
func Complete ¶
func Complete() bool
Complete tries to complete the command line that was already entered. It returns true on success, on which the main program should exit
Example ¶
ExampleComplete shows how bash completion works
package main import ( "os" "sync" "github.com/posener/flag" ) var once = sync.Once{} func chdir() { once.Do(func() { os.Chdir("tests") }) } func main() { chdir() // define a flag flag.File("file", "*.md", "", "file value") // set the environment variable used for setting the completion // look that there is a space after the '-file' flag, indicating that the user // want to complete by that flag os.Setenv("COMP_LINE", "demo -file ") // complete flag.Complete() }
Output: readme.md sub/ ./
func Dir ¶
Dir is a flag the relates to a directory on the filesystem according to a given pattern. For any directory name use "*" as the pattern.
func File ¶
File is a flag that is related to a file path on the filesystem according to a given pattern. for any file use "*" as the pattern.
func SetInstallFlags ¶
func SetInstallFlags(installName, uninstallName string)
SetInstallFlags adds to a flagset install and uninstall flags which invokes installation of bash completion in the user's home folder.
func StringCompleter ¶
StringCompleter is a string flag with custom bash completion
Types ¶
type CompleteFn ¶
CompleteFn is function implementing the Completer interface
type Completer ¶
type Completer interface { // Complete according to the given last string in the command line. // returns list of options to complete the last word in the command // line, and a boolean indicating if those options should be the // only shown options. Complete(last string) (options []string, only bool) }
Completer interface is for the Complete function
type FlagSet ¶
FlagSet is a copy of the standard library FlagSet struct.
func NewFlagSet ¶
func NewFlagSet(name string, h gflag.ErrorHandling) *FlagSet
NewFlagSet creates a new FlagSet
func (*FlagSet) Bool ¶
Bool defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.
func (*FlagSet) BoolVar ¶
BoolVar defines a bool flag with specified name, default value, and usage string. The argument s points to a bool variable in which to store the value of the flag.
func (*FlagSet) Complete ¶
Complete tries to complete the command line according to a FlagSet. It returns true on success, on which the main program should exit.
func (*FlagSet) Dir ¶
Dir is a flag the relates to a directory on the filesystem according to a given pattern. For any directory name use "*" as the pattern.
func (*FlagSet) File ¶
File is a flag that is related to a file path on the filesystem according to a given pattern. for any file use "*" as the pattern.
func (*FlagSet) SetInstallFlags ¶
SetInstallFlags adds to a flagset install and uninstall flags which invokes installation of bash completion in the user's home folder.