group

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {

	// Flags returns the FlagSet associated with the command. All the flags are
	// parsed before running the command.
	FlagSet() *flagset.FlagSet

	// Usages returns various usages that can be used for the command.
	Usages() []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.
	Help() string

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

	// 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.
	Init([]string, commands.CommandContext) error

	// Run should run the actual command with the given CLI instance and
	// command-line arguments. It should return the exit status when it is
	// finished.
	//
	// There are a handful of special exit codes that can return documented
	// behavioral changes.
	Run(*task.Group)
}

Command represents an abstraction of command.

type Group

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

Group holds the commands in a central repository for easy access.

func New

func New(options ...GroupOption) *Group

New creates a Group with sane defaults.

func (*Group) Add

func (r *Group) Add(key string, cmd Command) error

Add a Command to the Group for a given key. The key is normalized to remove trailing spaces for consistency. Returns an error when inserting into the Group fails

func (*Group) Get

func (r *Group) Get(key string) (Command, bool)

Get returns a Command for a given key. The key is normalized to remove trailing spaces for consistency. Returns true if it was found.

func (*Group) GetClosestName

func (r *Group) GetClosestName(key string) (string, bool)

GetClosestName returns the closest command to the given key

func (*Group) LongestPrefix

func (r *Group) LongestPrefix(key string) (string, bool)

LongestPrefix is like Get, but instead of an exact match, it will return the longest prefix match.

func (*Group) Nested

func (r *Group) Nested() bool

Nested returns if the commands with in the group are nested in anyway.

func (*Group) Process

func (r *Group) Process() error

Process runs through the registry and fills in any commands that are required for nesting (sub commands) Returns an error if there was an issue adding any commands to the underlying storage.

func (*Group) Remove

func (r *Group) Remove(key string) (Command, error)

Remove a Command from the Group for a given key. The key is normalized to remove trailing spaces for consistency. Returns an error when deleting from the Group upon failure

func (*Group) WalkPrefix

func (r *Group) WalkPrefix(prefix string, fn radix.WalkFn)

WalkPrefix is used to walk the tree under a prefix

type GroupOption

type GroupOption func(GroupOptions)

GroupOption captures a tweak that can be applied to the Group.

func OptionPlaceHolder

func OptionPlaceHolder(i PlaceHolder) GroupOption

OptionPlaceHolder allows the setting a place holder option to configure the group.

type GroupOptions

type GroupOptions interface {
	SetPlaceHolder(PlaceHolder)
}

GroupOptions represents a way to set optional values to a autocomplete option. The GroupOptions shows what options are available to change.

type PlaceHolder

type PlaceHolder func(string) Command

PlaceHolder is a type which is called when constructing the group and a place holder command is required.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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