Documentation ¶
Index ¶
- Variables
- func Usage() error
- type Arg
- type Args
- type Bool
- type CLI
- func (c CLI) Advanced() Command
- func (c CLI) Arg(name, help string) *Arg
- func (c CLI) Args(name string) *Args
- func (c CLI) Command(name, help string, runners ...Runner) Command
- func (c CLI) Flag(name, help string) *Flag
- func (c CLI) Hidden() Command
- func (c *CLI) Parse(ctx context.Context, args ...string) error
- func (c CLI) Run(fn func(ctx context.Context) error)
- func (c *CLI) Signals(signals ...os.Signal) *CLI
- func (c *CLI) Usage(usage *template.Template) *CLI
- func (c *CLI) Writer(w io.Writer) *CLI
- type Command
- type Custom
- type Flag
- func (f *Flag) Bool(target *bool) *Bool
- func (f *Flag) Custom(fn func(string) error) *Custom
- func (f *Flag) Int(target *int) *Int
- func (f *Flag) Optional() *OptionalFlag
- func (f *Flag) Short(short byte) *Flag
- func (f *Flag) String(target *string) *String
- func (f *Flag) StringMap(target *map[string]string) *StringMap
- func (f *Flag) Strings(target *[]string) *Strings
- type Int
- type OptionalArg
- type OptionalArgs
- type OptionalBool
- type OptionalFlag
- type OptionalInt
- type OptionalString
- type Parser
- type Runner
- type String
- type StringMap
- type Strings
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrCommandNotFound = errors.New("command not found")
Functions ¶
Types ¶
type Arg ¶
type Arg struct {
// contains filtered or unexported fields
}
func (*Arg) Optional ¶
func (a *Arg) Optional() *OptionalArg
type Args ¶
type Args struct { Name string // contains filtered or unexported fields }
func (*Args) Optional ¶
func (a *Args) Optional() *OptionalArgs
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "context" "os" "github.com/livebud/cli" ) func main() { flag := new(Flag) cli := cli.New("app", "your awesome cli").Writer(os.Stderr) cli.Flag("chdir", "change the dir").Short('C').String(&flag.Dir).Default(".") cli.Flag("embed", "embed the code").Bool(&flag.Embed).Default(false) { // new <dir> cmd := &New{Flag: flag} cli := cli.Command("new", "create a new project") cli.Arg("dir", "dir to serve from").String(&cmd.Flag.Dir) cli.Run(cmd.Run) } ctx := context.Background() cli.Parse(ctx, "new", "-h") } type Flag struct { Dir string Embed bool } type New struct { Flag *Flag } // Run new func (n *New) Run(ctx context.Context) error { return nil }
Output:
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
func (*Flag) Optional ¶
func (f *Flag) Optional() *OptionalFlag
type OptionalArg ¶
type OptionalArg struct {
// contains filtered or unexported fields
}
func (*OptionalArg) Bool ¶
func (a *OptionalArg) Bool(target **bool) *OptionalBool
func (*OptionalArg) Int ¶
func (a *OptionalArg) Int(target **int) *OptionalInt
func (*OptionalArg) String ¶
func (a *OptionalArg) String(target **string) *OptionalString
type OptionalArgs ¶
type OptionalArgs struct {
// contains filtered or unexported fields
}
func (*OptionalArgs) Strings ¶
func (a *OptionalArgs) Strings(target *[]string) *Strings
type OptionalBool ¶
type OptionalBool struct {
// contains filtered or unexported fields
}
func (*OptionalBool) Default ¶
func (v *OptionalBool) Default(value bool)
type OptionalFlag ¶
type OptionalFlag struct {
// contains filtered or unexported fields
}
func (*OptionalFlag) Bool ¶
func (f *OptionalFlag) Bool(target **bool) *OptionalBool
func (*OptionalFlag) Int ¶
func (f *OptionalFlag) Int(target **int) *OptionalInt
func (*OptionalFlag) String ¶
func (f *OptionalFlag) String(target **string) *OptionalString
func (*OptionalFlag) Strings ¶
func (f *OptionalFlag) Strings(target *[]string) *Strings
type OptionalInt ¶
type OptionalInt struct {
// contains filtered or unexported fields
}
func (*OptionalInt) Default ¶
func (v *OptionalInt) Default(value int)
type OptionalString ¶
type OptionalString struct {
// contains filtered or unexported fields
}
func (*OptionalString) Default ¶
func (v *OptionalString) Default(value string)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.