client

package
v0.0.0-...-cb6022a Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const Version = "0.0.4"

Version contains the client version number

Variables

View Source
var CmdRunner = NewRunner()

CmdRunner is the default command runner

Functions

This section is empty.

Types

type Args

type Args struct {
	Command string
	Params  []string
}

Args contains a command and its params

func (*Args) FirstParam

func (a *Args) FirstParam() string

FirstParam returns the first param. It returns empty string if there are no params.

func (*Args) IsParamsEmpty

func (a *Args) IsParamsEmpty() bool

IsParamsEmpty checks if the params size is 0

func (*Args) ParamsSize

func (a *Args) ParamsSize() int

ParamsSize returns the number of params

type Command

type Command struct {
	Run  func(cmd *Command, args *Args)
	Flag flag.FlagSet

	Key   string
	Usage string
	Short string
	Long  string
}

Command contains a function to run, a flagset, and usage instructions

func (*Command) Call

func (c *Command) Call(args *Args) (err error)

Call calls the command with provided args

func (*Command) FormattedUsage

func (c *Command) FormattedUsage() string

FormattedUsage returns the formatted usage for runnable command

func (*Command) Name

func (c *Command) Name() string

Name returns the name of the command. It falls back on the first word in Usage if no Name was provided.

func (*Command) PrintUsage

func (c *Command) PrintUsage()

PrintUsage prints usage instructions for the command

func (*Command) Runnable

func (c *Command) Runnable() bool

Runnable checks if the command has a Run function

type ExecError

type ExecError struct {
	Err      error
	ExitCode int
}

ExecError contains one error and an exit code.

func (*ExecError) Error

func (execError *ExecError) Error() string

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner contains a map of commands

func NewRunner

func NewRunner() *Runner

NewRunner creates a new Runner

func (*Runner) All

func (r *Runner) All() map[string]*Command

All returns all commands

func (*Runner) Call

func (r *Runner) Call(cmd *Command, args *Args) ExecError

Call calls a command with the given args

func (*Runner) Execute

func (r *Runner) Execute() ExecError

Execute executes a command

func (*Runner) Lookup

func (r *Runner) Lookup(name string) *Command

Lookup looks up a command with the given name

func (*Runner) Use

func (r *Runner) Use(command *Command)

Use adds the command to the runner

Jump to

Keyboard shortcuts

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