Documentation
¶
Overview ¶
Package cmd provides command file specs and structures used by an rce.Server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCommandNotFound = errors.New("command not found") ErrDuplicateName = errors.New("duplicate command name found") ErrDuplicateCommand = errors.New("duplicate command in repo") ErrRelativePath = errors.New("command uses relative path") ErrNoCommands = errors.New("no commands parsed") )
Functions ¶
This section is empty.
Types ¶
type Repo ¶
type Repo interface {
// Add new command to repo, identified by Cmd.Id.
Add(*Cmd) error
// Remove command from repo.
Remove(id string) error
// Return command from repo, or nil if doesn't exist.
Get(id string) *Cmd
// Return list of all command IDs in repos. The list is a copy and can change
// between calls.
All() []string
}
Repo is a thread-safe collection of Cmd used by an rce.Server.
type Runnable ¶
type Runnable []Spec
func LoadCommands ¶
LoadCommands loads all command Spec from a YAML config file. The file structure is:
---
commands:
- name: exit.zero
exec: [/usr/bin/true]
- name: exit.one
exec:
- /bin/false
- some-arg
Name must be unique. The first exec value must be an absolute command path. Additional exec values are optional and always included in the order listed.
func (Runnable) FindByName ¶
FindByName returns a Spec matching the given name.
func (Runnable) ValidateNoDuplicates ¶
ValidateNoDuplicates returns an ErrDuplicateName if the list of Spec contains duplicate names.
type Spec ¶
type Spec struct {
// Short, unique name of the command. Example: "lxc-ls". This is only an alias.
Name string `yaml:"name"`
// Exec args, first being the absolute cmd path. Example: ["/usr/bin/lxc-ls", "--active"].
Exec []string `yaml:"exec"`
}
Spec represents one command in a YAML config file. See LoadCommands for the file structure.
func (Spec) ValidateAbsPath ¶
ValidateAbsPath returns ErrRelativePath if the Spec's path is not an absolute path.