Version: v0.0.0-...-ce94876 Latest Latest

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

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 6 Imported by: 0



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.



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

This repository falls under the IPFS Code of Conduct.

Want to hack on IPFS?






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


This section is empty.


This section is empty.


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

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
t or T : Toggle theme light dark auto
y or Y : Canonical URL