Skip to content

Command Line Interface Program/FlagSet (subcommands and usage printing)

License

Notifications You must be signed in to change notification settings

codemodus/clip

Repository files navigation

clip

go get -u github.com/codemodus/clip 

Package clip provides simple command/subcommand structuring with a minimum of dependencies. The standard library flag.FlagSet type is leveraged often in this and related packages. If the FlagSet output is default, setting a help flag will result in usage output going to os.Stdout. Other parse errors will result in usage output going to os.Stderr as normal.

Usage

typeClipfuncNew(programstring, flags*FlagSet, subcmds*CommandSet) *Clipfunc (c*Clip) Parse(args []string) errorfunc (c*Clip) Run() errorfunc (c*Clip) Usage(depthint, errerror) errorfunc (c*Clip) UsageLongHelp(errerror) errortypeCommandfuncNewCommand(flags*FlagSet, fnHandlerFunc, subcmds*CommandSet) *CommandfuncNewCommandNamespace(namestring, subcmds*CommandSet) *CommandtypeCommandSetfuncNewCommandSet(cmds...*Command) *CommandSettypeFlagSetfuncNewFlagSet(namestring) *FlagSettypeHandlerFunctypeUsageErrorfuncAsUsageError(errerror) (UsageError, bool)

Setup

var ( globalCnf=newGlobalConf() printCnf=newPrintConf("print") otherCnf=newOtherConf("other") ) cs:=clip.NewCommandSet( clip.NewCommand(printCnf.flagSet, runPrintFunc(printCnf, globalCnf), nil), clip.NewCommand(otherCnf.flagSet, runOtherFunc(otherCnf), nil), ) app:=clip.New("myapp", globalCnf.flagSet, cs) // emulate cli command 'myapp -v print -msg="hello, world"'os.Args= []string{"myapp", "-v", "print", "-msg=hello, world"} iferr:=app.Parse(os.Args); err!=nil{returnapp.UsageLongHelp(err) } returnapp.Run()

More Info

N/A

Documentation

View the GoDoc

Benchmarks

N/A

About

Command Line Interface Program/FlagSet (subcommands and usage printing)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages