 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
- Variables
- func ClientError(msg string) error
- type Argument
- type ArgumentType
- type ChannelMarshaler
- type Command
- func (c *Command) Call(req Request) Response
- func (c *Command) CheckArguments(req Request) error
- func (c *Command) Get(path []string) (*Command, error)
- func (c *Command) GetOptions(path []string) (map[string]Option, error)
- func (c *Command) Resolve(path []string) ([]*Command, error)
- func (c *Command) Subcommand(id string) *Command
 
- type Context
- type EncodingType
- type Error
- type ErrorType
- type Function
- type HelpText
- type Marshaler
- type MarshalerMap
- type Option
- type OptionValue
- func (ov OptionValue) Bool() (value bool, found bool, err error)
- func (ov OptionValue) Definition() Option
- func (ov OptionValue) Float() (value float64, found bool, err error)
- func (ov OptionValue) Found() bool
- func (ov OptionValue) Int() (value int, found bool, err error)
- func (ov OptionValue) String() (value string, found bool, err error)
- func (ov OptionValue) Uint() (value uint, found bool, err error)
 
- type Request
- type Response
Constants ¶
const ( Invalid = reflect.Invalid Bool = reflect.Bool Int = reflect.Int Uint = reflect.Uint Float = reflect.Float64 String = reflect.String )
Types of Command options
const ( EncShort = "enc" EncLong = "encoding" RecShort = "r" RecLong = "recursive" ChanOpt = "stream-channels" )
Flag names
const ( JSON = "json" XML = "xml" Text = "text" )
Supported EncodingType constants.
Variables ¶
var ErrIncorrectType = errors.New("The command returned a value with a different type than expected")
    var ErrNoFormatter = ClientError("This command cannot be formatted to plain text")
    var ErrNotCallable = ClientError("This command can't be called directly. Try one of its subcommands.")
    ErrNotCallable signals a command that cannot be called.
var OptionEncodingType = StringOption(EncShort, EncLong, "The encoding type the output should be encoded with (json, xml, or text)")
    options that are used by this package
var OptionRecursivePath = BoolOption(RecShort, RecLong, "Add directory paths recursively")
    var OptionStreamChannels = BoolOption(ChanOpt, "Stream channel output")
    Functions ¶
func ClientError ¶
Types ¶
type Argument ¶
type Argument struct {
	Name          string
	Type          ArgumentType
	Required      bool // error if no value is specified
	Variadic      bool // unlimited values can be specfied
	SupportsStdin bool // can accept stdin as a value
	Recursive     bool // supports recursive file adding (with '-r' flag)
	Description   string
}
    func (Argument) EnableRecursive ¶
func (Argument) EnableStdin ¶
type ChannelMarshaler ¶
type Command ¶
type Command struct {
	Options    []Option
	Arguments  []Argument
	PreRun     func(req Request) error
	Run        Function
	PostRun    Function
	Marshalers map[EncodingType]Marshaler
	Helptext   HelpText
	// Type describes the type of the output of the Command's Run Function.
	// In precise terms, the value of Type is an instance of the return type of
	// the Run Function.
	//
	// ie. If command Run returns &Block{}, then Command.Type == &Block{}
	Type        interface{}
	Subcommands map[string]*Command
}
    Command is a runnable command, with input arguments and options (flags). It can also have Subcommands, to group units of work into sets.
func (*Command) CheckArguments ¶
func (*Command) GetOptions ¶
GetOptions gets the options in the given path of commands
func (*Command) Subcommand ¶
Subcommand returns the subcommand with the given id
type Context ¶
type Context struct {
	// this Context is temporary. Will be replaced soon, as we get
	// rid of this variable entirely.
	Context context.Context
	Online     bool
	ConfigRoot string
	LoadConfig func(path string) (*config.Config, error)
	ConstructNode func() (*core.IpfsNode, error)
	// contains filtered or unexported fields
}
    func (*Context) GetConfig ¶
GetConfig returns the config of the current Command exection context. It may load it with the providied function.
func (*Context) GetNode ¶
GetNode returns the node of the current Command exection context. It may construct it with the providied function.
func (*Context) NodeWithoutConstructing ¶
NodeWithoutConstructing returns the underlying node variable so that clients may close it.
type Function ¶
Function is the type of function that Commands use. It reads from the Request, and writes results to the Response.
type HelpText ¶
type HelpText struct {
	// required
	Tagline          string // used in <cmd usage>
	ShortDescription string // used in DESCRIPTION
	Synopsis         string // showcasing the cmd
	// optional - whole section overrides
	Usage           string // overrides USAGE section
	LongDescription string // overrides DESCRIPTION section
	Options         string // overrides OPTIONS section
	Arguments       string // overrides ARGUMENTS section
	Subcommands     string // overrides SUBCOMMANDS section
}
    HelpText is a set of strings used to generate command help text. The help text follows formats similar to man pages, but not exactly the same.
type Marshaler ¶
Marshaler is a function that takes in a Response, and returns an io.Reader (or an error on failure)
type MarshalerMap ¶
type MarshalerMap map[EncodingType]Marshaler
MarshalerMap is a map of Marshaler functions, keyed by EncodingType (or an error on failure)
type Option ¶
type Option interface {
	Names() []string     // a list of unique names matched with user-provided flags
	Type() reflect.Kind  // value must be this type
	Description() string // a short string that describes this option
}
    Option is used to specify a field that will be provided by a consumer
func BoolOption ¶
func FloatOption ¶
func StringOption ¶
func UintOption ¶
type OptionValue ¶
type OptionValue struct {
	// contains filtered or unexported fields
}
    func (OptionValue) Bool ¶
func (ov OptionValue) Bool() (value bool, found bool, err error)
value accessor methods, gets the value as a certain type
func (OptionValue) Definition ¶
func (ov OptionValue) Definition() Option
Definition returns the option definition for the provided value
func (OptionValue) Found ¶
func (ov OptionValue) Found() bool
Found returns true if the option value was provided by the user (not a default value)
type Request ¶
type Request interface {
	Path() []string
	Option(name string) *OptionValue
	Options() optMap
	SetOption(name string, val interface{})
	SetOptions(opts map[string]interface{}) error
	Arguments() []string
	SetArguments([]string)
	Files() files.File
	SetFiles(files.File)
	Context() *Context
	SetContext(Context)
	Command() *Command
	Values() map[string]interface{}
	Stdin() io.Reader
	ConvertOptions() error
}
    Request represents a call to a command from a consumer
func NewEmptyRequest ¶
NewEmptyRequest initializes an empty request
type Response ¶
type Response interface {
	Request() Request
	// Set/Return the response Error
	SetError(err error, code ErrorType)
	Error() *Error
	// Sets/Returns the response value
	SetOutput(interface{})
	Output() interface{}
	// Sets/Returns the length of the output
	SetLength(uint64)
	Length() uint64
	// Marshal marshals out the response into a buffer. It uses the EncodingType
	// on the Request to chose a Marshaler (Codec).
	Marshal() (io.Reader, error)
	// Gets a io.Reader that reads the marshalled output
	Reader() (io.Reader, error)
	// Gets Stdout and Stderr, for writing to console without using SetOutput
	Stdout() io.Writer
	Stderr() io.Writer
}
    Response is the result of a command request. Handlers write to the response, setting Error or Value. Response is returned to the client.
func NewResponse ¶
NewResponse returns a response to match given Request