Documentation ¶
Overview ¶
Package base defines shared basic pieces of the commands, in particular logging and the Command structure.
Index ¶
- Variables
- func Errorf(format string, args ...interface{})
- func Execute()
- func Exit()
- func ExitIfErrors()
- func Fatalf(format string, args ...interface{})
- func GetExitStatus() int
- func Help(w io.Writer, args []string)
- func PrintUsage(w io.Writer, cmd *Command)
- func RegisterCommand(cmd *Command)
- func SetExitStatus(n int)
- func Sort()
- type Command
- type CommandEnvHolder
Constants ¶
This section is empty.
Variables ¶
var SortLessFunc = func(i, j *Command) bool {
return i.Name() < j.Name()
}
SortLessFunc used for sort commands list, can be override from outside
Functions ¶
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs error and set exit status to 1, but not exit
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs error and exit with code 1
func RegisterCommand ¶
func RegisterCommand(cmd *Command)
RegisterCommand register a command to RootCommand
Types ¶
type Command ¶
type Command struct { // Run runs the command. // The args are the arguments after the command name. Run func(cmd *Command, args []string) // UsageLine is the one-line usage message. // The words between the first word (the "executable name") and the first flag or argument in the line are taken to be the command name. // // UsageLine supports go template syntax. It's recommended to use "{{.Exec}}" instead of hardcoding name UsageLine string // Short is the short description shown in the 'go help' output. // // Note: Short does not support go template syntax. Short string // Long is the long message shown in the 'go help <this-command>' output. // // Long supports go template syntax. It's recommended to use "{{.Exec}}", "{{.LongName}}" instead of hardcoding strings Long string // Flag is a set of flags specific to this command. Flag flag.FlagSet // CustomFlags indicates that the command will do its own // flag parsing. CustomFlags bool // Commands lists the available commands and help topics. // The order here is the order in which they are printed by 'go help'. // Note that subcommands are in general best avoided. Commands []*Command }
A Command is an implementation of a xray command like xray run or xray version.
var RootCommand *Command
RootCommand is the root command of all commands
func (*Command) LongName ¶
LongName returns the command's long name: all the words in the usage line between first word (e.g. "xray") and a flag or argument,
func (*Command) Name ¶
Name returns the command's short name: the last word in the usage line before a flag or argument.
type CommandEnvHolder ¶
type CommandEnvHolder struct { // Executable name of current binary Exec string // commands column width of current command CommandsWidth int }
CommandEnvHolder is a struct holds the environment info of commands
var CommandEnv CommandEnvHolder
CommandEnv holds the environment info of commands