Documentation ¶
Overview ¶
Package cli is a package to build CLI programs.
eg:
func main() { opts := struct { Foo string `env:"FOO" help:"A simple string."` Bar int `env:"BAR" help:"A simple integer."` }{ Foo: "foo", Bar: 42, } ctx, cancel := cli.ContextWithSignals(context.Background(), os.Interrupt, syscall.SIGTERM, ) defer cancel() cli.Register(). Help("A simple command"). Options(&opts) cli.Register("hello"). Help("A sub command"). Options(&opts) cli.Register("world"). Help("Another sub command"). Options(&opts) switch cli.Load() { case "hello": helloCmd(ctx, opts) case "world": worldCmd(ctx, opts) default: defaultCmd(ctx, opts) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithSignals ¶
func ContextWithSignals(parent context.Context, sig ...os.Signal) (ctx context.Context, cancel func())
ContextWithSignals returns a copy of the parent context that gets canceled when one of the specified signals is emitted. If no signals are provided, all incoming signals will cancel the context.
Canceling this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete.
Types ¶
Click to show internal directories.
Click to hide internal directories.