Overview ▹
Overview ▾
Package cmdmain contains the shared implementation for pk-get, pk-put, pk, and other Perkeep command-line tools.
Index
- Variables
- func Errorf(format string, args ...interface{})
- func Logf(format string, v ...interface{})
- func Main()
- func PrintLicenses()
- func Printf(format string, args ...interface{})
- func RegisterCommand(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner)
- func RegisterMode(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner)
- type CommandRunner
- type Demoter
- type ExecRunner
- type UsageError
- func (ue UsageError) Error() string
Package files
Variables
var (
FlagVersion = flag.Bool("version", false, "show version")
FlagHelp = flag.Bool("help", false, "print usage")
FlagVerbose = flag.Bool("verbose", false, "extra debug logging")
FlagLegal = flag.Bool("legal", false, "show licenses")
)
var (
// ExtraFlagRegistration allows to add more flags from
// other packages (with AddFlags) when Main starts.
ExtraFlagRegistration = func() {}
// PostFlag runs code that needs to happen after flags were parsed, but
// before the subcommand is run.
PostFlag = func() {}
// PreExit runs after the subcommand, but before Main terminates
// with either success or the error from the subcommand.
PreExit = func() {}
// ExitWithFailure determines whether the command exits
// with a non-zero exit status.
ExitWithFailure bool
)
var (
// Indirections for replacement by tests
Stderr io.Writer = os.Stderr
Stdout io.Writer = os.Stdout
Stdin io.Reader = os.Stdin
Exit = realExit
)
var ErrUsage = UsageError("invalid command")
func Errorf
func Errorf(format string, args ...interface{})
Errorf prints to Stderr, regardless of FlagVerbose.
func Logf
func Logf(format string, v ...interface{})
Logf logs to Stderr if FlagVerbose, and is silent otherwise.
func Main
func Main()
Main is meant to be the core of a command that has subcommands (modes), such as pk-put or pk.
func PrintLicenses
func PrintLicenses()
PrintLicenses prints all the licences registered by go4.org/legal for this program.
func Printf
func Printf(format string, args ...interface{})
Printf prints to Stderr if FlagVerbose, and is silent otherwise.
func RegisterCommand
func RegisterCommand(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner)
RegisterCommand adds a mode to the list of modes for the main command, and also specifies that this mode is just another executable that runs as a new cmdmain command. The executable to run is determined by the LookPath implementation for this mode.
func RegisterMode
func RegisterMode(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner)
RegisterMode adds a mode to the list of modes for the main command. It is meant to be called in init() for each subcommand.
type CommandRunner
type CommandRunner interface {
Usage()
RunCommand(args []string) error
}
CommandRunner is the type that a command mode should implement.
type Demoter
type Demoter interface {
CommandRunner
Demote() bool
}
Demoter is an interface that boring commands can implement to demote themselves in the tool listing, for boring or low-level subcommands. They only show up in --help mode.
type ExecRunner
type ExecRunner interface {
CommandRunner
LookPath() (string, error)
}
ExecRunner is the type that a command mode should implement when that mode just calls a new executable that will run as a new command.
type UsageError
type UsageError string
func (UsageError) Error
func (ue UsageError) Error() string
