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, help string) *Args
- func (c CLI) Command(name, help string) 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 Enum
- type EnumValue
- type Flag
- func (f *Flag) Bool(target *bool) *Bool
- func (f *Flag) Custom(fn func(string) error) *Custom
- func (f *Flag) Enum(target *string, possibilities ...string) *Enum
- 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 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 {
// 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" ) type appCmd struct { Chdir string Embed bool } type newCmd struct { Dir string Minify bool } // Run new func (c *newCmd) Run(ctx context.Context) error { os.Stdout.WriteString("running new on " + c.Dir) return nil } func main() { cmd := &appCmd{} cli := cli.New("app", "your awesome cli").Writer(os.Stderr) cli.Flag("chdir", "change the dir").Short('C').String(&cmd.Chdir).Default(".") cli.Flag("embed", "embed the code").Bool(&cmd.Embed).Default(false) { // new <dir> cmd := &newCmd{} cli := cli.Command("new", "create a new project") cli.Arg("dir", "directory to scaffold in").String(&cmd.Dir) cli.Run(cmd.Run) } ctx := context.Background() cli.Parse(ctx, "new", ".") }
Output: running new on .
type EnumValue ¶ added in v0.0.5
type EnumValue struct {
// contains filtered or unexported fields
}
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.