targets

package
v0.0.0-...-080782a Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2014 License: ISC Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSONCommands

func ParseJSONCommands(jsonstr string) (map[string]*Command, error)

ParseJSONCommands parses a json structure into a map structure that the Commands() function is expected to return

func RegisterTarget

func RegisterTarget(name string, creator CreateTarget)

RegisterTarget is used by targets to register itself

Types

type Command

type Command struct {
	Name        string              `json"-"`
	Description string              `json:"description"`
	Parameters  []*CommandParameter `json:"parameters"`
}

Command represents an target command

func NewCommand

func NewCommand(desc string, param ...*CommandParameter) *Command

NewCommand creates a new Command structure

type CommandError

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

CommandError is a structure representing an error when executing a command

func NewCommandError

func NewCommandError(tgt string, tgtfound bool, cmd string, cmdfound bool, prms []string) *CommandError

NewCommandError creates a new commanderror

func (*CommandError) Command

func (c *CommandError) Command() string

Command returns the command that failed

func (*CommandError) CommandFound

func (c *CommandError) CommandFound() bool

CommandFound returns if the command that failed existed or not

func (CommandError) Error

func (c CommandError) Error() string

Error returns the error description string for the command that failed

func (*CommandError) Params

func (c *CommandError) Params() []string

Params returns the parameters passed to the command that failed

func (*CommandError) Target

func (c *CommandError) Target() string

Target returns the target of the command that failed

func (*CommandError) TargetFound

func (c *CommandError) TargetFound() bool

TargetFound returns if the target of the command that failed existed or not

type CommandParameter

type CommandParameter struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
	Validation  string `json:"validation"`
	Optional    bool   `json:"optional"`
	// contains filtered or unexported fields
}

CommandParameter represents a parameter that can be passed to a Command and validated using a validation function

func NewParameter

func NewParameter(name, desc string) *CommandParameter

NewParameter creates a new parameter structure

func (*CommandParameter) SetCustom

func (c *CommandParameter) SetCustom(validation string, fnc ParameterValidator) *CommandParameter

SetCustom changes the type of the parameter to be custom with a custom validation function.

func (*CommandParameter) SetList

func (c *CommandParameter) SetList(list ...string) *CommandParameter

SetList changes the type of the parameter to be a list value. The parameters passed are the possible values that the parameter can have

func (*CommandParameter) SetNumeric

func (c *CommandParameter) SetNumeric() *CommandParameter

SetNumeric changes the type of the parameter to be numeric. A numeric parameter can be passed in hex (0x##), octal (0#) or decimal (##) notation

func (*CommandParameter) SetOptional

func (c *CommandParameter) SetOptional() *CommandParameter

SetOptional sets this Command Parameter to be optional

func (*CommandParameter) SetRange

func (c *CommandParameter) SetRange(start, end int) *CommandParameter

SetRange changes the type of the parameter to be a range with a start and end value

func (*CommandParameter) SetRegex

func (c *CommandParameter) SetRegex(regex string) *CommandParameter

SetRegex changes the type of the parameter to be a string matching a given regular expression.

func (*CommandParameter) SetString

func (c *CommandParameter) SetString() *CommandParameter

SetString changes the type of the parameter to be a string. Almost no validation is performed

func (*CommandParameter) Validate

func (c *CommandParameter) Validate(value string) (string, error)

Validate performs a default validation based on the type of the command parameter

type CreateTarget

type CreateTarget func(name string, params map[string]string) (t Target, err error)

CreateTarget is a function definition each target must provide during registration

type ParameterValidator

type ParameterValidator func(value, validation string) (string, error)

ParameterValidator is the function definition used to validate a value with the given validation string

type Target

type Target interface {
	SendCommand(cmd string, args ...string) error
	Stop() error
	Commands() map[string]*Command
}

Target is an interface which every Target must implement

type TargetManager

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

TargetManager is the structure which manages all targets

func NewTargetManager

func NewTargetManager(m *modes.Modes) *TargetManager

NewTargetManager creates and initialize a new TargetManager object

func (*TargetManager) Add

func (t *TargetManager) Add(module, name string, params map[string]string) error

Add adds a new target using the specified module, given the specified name and parameters

func (*TargetManager) Remove

func (t *TargetManager) Remove(name string) error

Remove removes a target instance from the list

func (*TargetManager) RunCommand

func (t *TargetManager) RunCommand(cmdstring string) error

RunCommand parses a given command, determines which target should run it, checks the provided parameters, and if all is good - run the command.

func (*TargetManager) Stop

func (t *TargetManager) Stop() error

Stop stops all target instances and removes them

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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