commands

package
v0.0.0-...-5d27ecb Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Disguard = func(err error) {}

Disguard is used as a High Order Function to disguard error messages

View Source
var (
	// ErrShowHelp is a sentinel error message for showing help.
	ErrShowHelp = errors.New("show help")
)
View Source
var Nothing = func(g *group.Group) {
	g.Add(func(context.Context) error { return nil }, Disguard)
}

Nothing is used as a High Order Function to consume all group event runs into nothing.

Functions

This section is empty.

Types

type CommandContext

type CommandContext struct {
	Debug   bool
	DevMode bool
}

CommandContext is the context the command was run with.

type Runnable

type Runnable interface {
	// Run runs the actual CLI bases on the arguments given.
	Run(args []string) (int, error)
}

Runnable allows the shell to interact with a given runnable type.

type Shell

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

Shell defines a REPL that can be interactively accessed.

func NewShell

func NewShell(runner Runnable, group Store) *Shell

NewShell creates a REPL from a runnable and a command store.

func (*Shell) FlagSet

func (c *Shell) FlagSet() *flagset.FlagSet

FlagSet returns the FlagSet associated with the command. All the flags are parsed before running the command.

func (*Shell) Help

func (c *Shell) Help() string

Help should return a long-form help text that includes the command-line usage. A brief few sentences explaining the function of the command, and the complete list of flags the command accepts.

func (*Shell) Init

func (c *Shell) Init([]string, CommandContext) error

Init is called with all the args required to run a command. This is separated from Run, to allow the preperation of a command, before it's run.

func (*Shell) Run

func (c *Shell) Run(group *group.Group)

Run subscribes to the group for executing the various run commands. The subscriptions to the group are handled by the callee.

func (*Shell) Synopsis

func (c *Shell) Synopsis() string

Synopsis should return a one-line, short synopsis of the command. This should be short (50 characters of less ideally).

func (*Shell) Usages

func (c *Shell) Usages() []string

Usages returns various usages that can be used for the command.

type Store

type Store interface {
	// WalkPrefix is used to walk the tree under a prefix
	WalkPrefix(prefix string, fn radix.WalkFn)
}

Store holds the command prefixes to able to walk over.

type Text

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

Text defines a simple text based command, that can be useful for creating commands that require more text based explanations.

func NewText

func NewText(help, synopsis string) *Text

NewText creates a Command with sane defaults

func (*Text) FlagSet

func (c *Text) FlagSet() *flagset.FlagSet

FlagSet returns the FlagSet associated with the command. All the flags are parsed before running the command.

func (*Text) Help

func (c *Text) Help() string

Help should return a long-form help text that includes the command-line usage. A brief few sentences explaining the function of the command, and the complete list of flags the command accepts.

func (*Text) Init

func (c *Text) Init([]string, CommandContext) error

Init is called with all the args required to run a command. This is separated from Run, to allow the preperation of a command, before it's run.

func (*Text) Run

func (c *Text) Run(group *group.Group)

Run subscribes to the group for executing the various run commands. The subscriptions to the group are handled by the callee.

func (*Text) Synopsis

func (c *Text) Synopsis() string

Synopsis should return a one-line, short synopsis of the command. This should be short (50 characters of less ideally).

func (*Text) Usages

func (c *Text) Usages() []string

Usages returns various usages that can be used for the command.

Jump to

Keyboard shortcuts

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