Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

cobra

v0.0.0-20140117131931-1e1ff9e35e12
github.com/kdar/cobra

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

46 matches

Top ↑

Functions

Eq

func Eq(a interface{}, b interface{}) bool

Gt

func Gt(a interface{}, b interface{}) bool

Types

Command

type Command struct {

	// The one-line usage message.
	Use string
	// The short description shown in the 'help' output.
	Short string
	// The long message shown in the 'help <this-command>' output.
	Long string

	// Run runs the command.
	// The args are the arguments after the command name.
	Run func(cmd *Command, args []string)
	// contains filtered or unexported fields
}

Command is just that, a command for your application. eg. 'go run' ... 'run' is the command. Cobra requires you to define the usage and description as part of your command definition to ensure usability.

Command.AddCommand

func (c *Command) AddCommand(cmds ...*Command)

Add one or many commands as children of this

Command.CommandPath

func (c *Command) CommandPath() string

The full path to this command

Command.CommandPathPadding

func (c *Command) CommandPathPadding() int

Command.Commands

func (c *Command) Commands() []*Command

Command.DebugFlags

func (c *Command) DebugFlags()

For use in determining which flags have been assigned to which commands and which persist

Command.Execute

func (c *Command) Execute() (err error)

Call execute to use the args (os.Args[1:] by default) and run through the command tree finding appropriate matches for commands and then corresponding flags.

Command.Find

func (c *Command) Find(arrs []string) (*Command, []string, error)

find the target command given the args and command tree Meant to be run on the highest node. Only searches down.

Command.Flag

func (c *Command) Flag(name string) (flag *flag.Flag)

Climbs up the command tree looking for matching flag

Command.Flags

func (c *Command) Flags() *flag.FlagSet

Get the Commands FlagSet

Command.HasFlags

func (c *Command) HasFlags() bool

Does the command contain flags (local not persistent)

Command.HasParent

func (c *Command) HasParent() bool

Determine if the command is a child command

Command.HasPersistentFlags

func (c *Command) HasPersistentFlags() bool

Does the command contain persistent flags

Command.HasSubCommands

func (c *Command) HasSubCommands() bool

Determine if the command has children commands

Command.Help

func (c *Command) Help() error

Output the help for the command Used when a user calls help [command] by the default HelpFunc in the commander

Command.HelpFunc

func (c *Command) HelpFunc() func(*Command, []string)

Command.HelpTemplate

func (c *Command) HelpTemplate() string

Command.Name

func (c *Command) Name() string

Name returns the command's name: the first word in the use line.

Command.Out

func (c *Command) Out() io.Writer

Command.Parent

func (c *Command) Parent() *Command

Command.ParseFlags

func (c *Command) ParseFlags(args []string) (err error)

Parses persistent flag tree & local flags

Command.PersistentFlags

func (c *Command) PersistentFlags() *flag.FlagSet

Get the Commands Persistent FlagSet

Command.Print

func (c *Command) Print(i ...interface{})

Convenience method to Print to the defined output

Command.Printf

func (c *Command) Printf(format string, i ...interface{})

Convenience method to Printf to the defined output

Command.Println

func (c *Command) Println(i ...interface{})

Convenience method to Println to the defined output

Command.ResetCommands

func (c *Command) ResetCommands()

Used for testing

Command.ResetFlags

func (c *Command) ResetFlags()

For use in testing

Command.Root

func (c *Command) Root() *Command

Command.Runnable

func (c *Command) Runnable() bool

Determine if the command is itself runnable

Command.SetArgs

func (c *Command) SetArgs(a []string)

os.Args[1:] by default, if desired, can be overridden particularly useful when testing.

Command.SetHelpCommand

func (c *Command) SetHelpCommand(cmd *Command)

Command.SetHelpFunc

func (c *Command) SetHelpFunc(f func(*Command, []string))

Can be defined by Application

Command.SetHelpTemplate

func (c *Command) SetHelpTemplate(s string)

Can be defined by Application

Command.SetOutput

func (c *Command) SetOutput(output io.Writer)

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.

Command.SetUsageFunc

func (c *Command) SetUsageFunc(f func(*Command) error)

Usage can be defined by application

Command.SetUsageTemplate

func (c *Command) SetUsageTemplate(s string)

Can be defined by Application

Command.Usage

func (c *Command) Usage() error

Output the usage for the command Used when a user provides invalid input Can be defined by user by overriding UsageFunc

Command.UsageFunc

func (c *Command) UsageFunc() (f func(*Command) error)

Command.UsagePadding

func (c *Command) UsagePadding() int

Command.UsageString

func (c *Command) UsageString() string

Command.UsageTemplate

func (c *Command) UsageTemplate() string

Command.UseLine

func (c *Command) UseLine() string

The full usage for a given command (including parents)

Dependency graph