cli

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCommandExecutionError added in v0.2.0

func ExitCommandExecutionError()

ExitCommandExecutionError exits with the exit code to return when an error occurred when executing a command.

func ExitCommandInterpretationError added in v0.2.0

func ExitCommandInterpretationError()

ExitCommandInterpretationError exits with the exit code to return when there was an error interpreting the command typed by the user. Should technically be returned if the help message will be printed and the user didn't explicitly request for the help message to be printed.

func ParseArgs added in v0.2.0

func ParseArgs(command Command, args []string)

ParseArgs recursively parses arguments through the command hierarchy until it gets to the subcommand that needs to be executed

func PrintHelp added in v0.2.0

func PrintHelp(command Command, exitWithError bool)

PrintHelp prints the help message for the provided command. If exitWithError is set to true, then the command exits with a command interpretation error status code

Types

type Command

type Command interface {
	// Init initializes the command. Place all initialization code here. Function should be
	// called when initializing the command hierarch (if sub-command, within the parent command's
	// Init function).
	Init(helpFlagName string, helpFlagDescription string)
	// GetName returns the name of the command. This is what will be displayed when a user requests to see
	// the command's manual.
	GetName() string
	// GetDescription returns the description of the command. This is what will be displayed when a user requests to
	// see the command's manual.
	GetDescription() string
	// GetFlagSet returns flag.FlagSet holding arguments linked to the command. If command's arguments linked to
	// the default FlagSet, then return nil.
	GetFlagSet() *flag.FlagSet
	// GetSubCommands returns a list sub-commands that are children of this command.
	GetSubCommands() []Command
	// GetHelpFlag returns a pointer to the bool linked to the command's help flag.
	GetHelpFlag() *bool
	// Process executes the logic for the command. If command has sub-commands, this function will never be called.
	Process()
}

Command is the interface to implement if you want to define a (sub)command

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL