cmdkit

package
v0.0.0-...-8b9b725 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT, MIT Imports: 6 Imported by: 46

README

go-ipfs-cmdkit

standard-readme compliant

tools used by go-ipfs-cmds and go-ipfs/commands

cmdkit offers some types, functions and values that are shared between go-ipfs/commands and its rewrite go-ipfs-cmds.

Documentation

https://godoc.org/github.com/ipfs/go-ipfs-cmdkit

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?

License

MIT

Documentation

Index

Constants

View Source
const (
	Invalid = reflect.Invalid
	Bool    = reflect.Bool
	Int     = reflect.Int
	Uint    = reflect.Uint
	Int64   = reflect.Int64
	Uint64  = reflect.Uint64
	Float   = reflect.Float64
	String  = reflect.String
)

Types of Command options

Variables

This section is empty.

Functions

This section is empty.

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 FileArg

func FileArg(name string, required, variadic bool, description string) Argument

func StringArg

func StringArg(name string, required, variadic bool, description string) Argument

func (Argument) EnableRecursive

func (a Argument) EnableRecursive() Argument

func (Argument) EnableStdin

func (a Argument) EnableStdin() Argument

type ArgumentType

type ArgumentType int
const (
	ArgString ArgumentType = iota
	ArgFile
)

type Error

type Error struct {
	Message string
	Code    ErrorType
}

Error is a struct for marshalling errors

func Errorf

func Errorf(code ErrorType, format string, args ...interface{}) Error

Errorf returns an Error with the given code and format specification

func (Error) Error

func (e Error) Error() string

func (Error) MarshalJSON

func (e Error) MarshalJSON() ([]byte, error)

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(data []byte) error

type ErrorType

type ErrorType uint

ErrorType signfies a category of errors

const (
	ErrNormal         ErrorType = iota // general errors
	ErrClient                          // error was caused by the client, (e.g. invalid CLI usage)
	ErrImplementation                  // programmer error in the server
	ErrNotFound                        // == HTTP 404
	ErrFatal                           // abort instantly

)

ErrorTypes convey what category of error ocurred

type HelpText

type HelpText struct {
	// required
	Tagline               string            // used in <cmd usage>
	ShortDescription      string            // used in DESCRIPTION
	SynopsisOptionsValues map[string]string // mappings for synopsis generator

	// 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
	Synopsis        string // overrides SYNOPSIS field
}

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 OptMap

type OptMap map[string]interface{}

type Option

type Option interface {
	Name() string    // the main name of the option
	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

	WithDefault(interface{}) Option // sets the default value of the option
	Default() interface{}

	Parse(str string) (interface{}, error)
}

Option is used to specify a field that will be provided by a consumer

func BoolOption

func BoolOption(names ...string) Option

func FloatOption

func FloatOption(names ...string) Option

func Int64Option

func Int64Option(names ...string) Option

func IntOption

func IntOption(names ...string) Option

func NewOption

func NewOption(kind reflect.Kind, names ...string) Option

constructor helper functions

func StringOption

func StringOption(names ...string) Option

func Uint64Option

func Uint64Option(names ...string) Option

func UintOption

func UintOption(names ...string) Option

type OptionValue

type OptionValue struct {
	Value      interface{}
	ValueFound bool
	Def        Option
}

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) Float

func (ov *OptionValue) Float() (value float64, found bool, err error)

func (*OptionValue) Found

func (ov *OptionValue) Found() bool

Found returns true if the option value was provided by the user (not a default value)

func (*OptionValue) Int

func (ov *OptionValue) Int() (value int, found bool, err error)

func (*OptionValue) Int64

func (ov *OptionValue) Int64() (value int64, found bool, err error)

func (*OptionValue) String

func (ov *OptionValue) String() (value string, found bool, err error)

func (*OptionValue) Uint

func (ov *OptionValue) Uint() (value uint, found bool, err error)

func (*OptionValue) Uint64

func (ov *OptionValue) Uint64() (value uint64, found bool, err error)

Jump to

Keyboard shortcuts

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