Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArgumentConfig ¶ added in v0.0.2
type ArgumentConfig struct { Name string // Required. Description string // Optional. Used for the help command. Required bool // Optional. Default: false. Required arguments cannot be added after optional ones. }
Configure a positional argument in clio.
type Cli ¶
type Cli struct { Name string // Required. Description string // Optional. Used for the built in help command to give your users information about your application. SubCommands []Command // Optional. SetupHandler Setup // Optional. Define the function executed during the execution of your CLI. Defaults to setup command with HelpHandler. EnableHelpCommand bool // Optional. Default: false. Enable clio's builtin help command. }
The core struct for your CLI application.
func (Cli) Run ¶
func (c Cli) Run()
Call Cli.Run() in your main function to execute your CLI.
Example ¶
package main import ( "github.com/probablyanewt/fire/pkg/clio" "github.com/probablyanewt/fire/pkg/loggo" ) var myCli = clio.Cli{ Name: "mycli", SetupHandler: func(clio *clio.Context) clio.Handler { return func() error { loggo.Info("Hello world") return nil } }, } func main() { myCli.Run() }
Output:
func (Cli) Validate ¶
func (c Cli) Validate()
Call Cli.Validate() in a main function, to validate your CLI configuration.
As the Run function also validates the CLI before executing, you should call this before building your CLI into a binary, in order to ensure it is error free.
Example ¶
package main import ( "github.com/probablyanewt/fire/pkg/clio" "github.com/probablyanewt/fire/pkg/loggo" ) var myCli = clio.Cli{ Name: "mycli", SetupHandler: func(clio *clio.Context) clio.Handler { return func() error { loggo.Info("Hello world") return nil } }, } func main() { myCli.Validate() }
Output:
type Command ¶
type Command struct { Name string // Required. Description string // Optional. Used for the built in help command to give your users information about your Command. The first sentence will be used as a snippet to be displayed in the help command of the parent command. SubCommands []Command // Optional. SetupHandler Setup // Optional. Define the function executed during the execution of your Command. Defaults to setup with HelpHandler. }
Use Command to define SubCommands for your CLI.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) AddArgument ¶ added in v0.0.2
func (c *Context) AddArgument(config ArgumentConfig) *string
Add a positional argument to the command. Returns a reference to the location where the argument will be stored.
func (*Context) AddFlag ¶
func (c *Context) AddFlag(config FlagConfig) *bool
Add a flag to the command. Returns a reference to the lcoation where the flag will be stored.
func (*Context) AddStringFlag ¶
func (c *Context) AddStringFlag(config FlagConfig) *string
Add a string flag to the command. Returns a reference to the lcoation where the flag will be stored.
type FlagConfig ¶
type FlagConfig struct { Name string // Required. Description string // Optional. Used for the help command. Alias byte // Optional. }
Configure a flag in clio.
type Handler ¶
type Handler func() error
The function signature executed when the command is called.
func HelpHandler ¶ added in v0.0.2
HelpHandler will put this command in help only mode. So if this command is exectued, it will instead just show the help page for this command instead. Use this function as the value for SetupHandler.
func OnlySubCommandHandler ¶ added in v0.0.2
OnlySubCommandHandler will put this command into sub command only mode. So if this command is exectued, it will instead error informing the user that a sub command is required. Use this function as the value for SetupHandler.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
Package compile_options implements compile time options for clio using Go's build tags feature.
|
Package compile_options implements compile time options for clio using Go's build tags feature. |
examples
|
|