getopt

package
v0.0.0-...-04f0340 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const DESCRIPTION = "description"
View Source
const HIDE_OPERANDS = "hideOperands"
View Source
const MAX_WIDTH = "maxWidth"
View Source
const MULTIPLE = 2
View Source
const MULTIPLE_ARGUMENT = ":multipleArg"
View Source
const NO_ARGUMENT = ":noArg"
View Source
const OPTIONAL = 0
View Source
const OPTIONAL_ARGUMENT = ":optionalArg"
View Source
const REQUIRED = 1
View Source
const REQUIRED_ARGUMENT = ":requiredArg"
View Source
const TRANSLATION_KEY = "operand"

Variables

View Source
var SETTING_COMMAND_NAME = "scriptName"
View Source
var SETTING_DEFAULT_MODE = "defaultMode"
View Source
var SETTING_STRICT_OPERANDS = "strictOperands"
View Source
var SETTING_STRICT_OPTIONS = "strictOptions"

Functions

func FileIsReadable

func FileIsReadable(args ...string) bool

func Translate

func Translate(key string) string

Types

type Argument

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

func NewArgument

func NewArgument(defaultValue *string, callable *validationFunc, nameArg *string) *Argument

func (*Argument) Describe

func (a *Argument) Describe() string

func (*Argument) GetDefaultValue

func (a *Argument) GetDefaultValue() []string

func (*Argument) GetName

func (a *Argument) GetName() string

func (*Argument) GetValidationMessage

func (a *Argument) GetValidationMessage(value ...string) string

func (*Argument) GetValue

func (a *Argument) GetValue() []string

func (*Argument) HasDefaultValue

func (a *Argument) HasDefaultValue() bool

func (*Argument) HasValidation

func (a *Argument) HasValidation() bool

func (*Argument) IsMultiple

func (a *Argument) IsMultiple() bool

func (*Argument) Multiple

func (a *Argument) Multiple(m bool) *Argument

func (*Argument) SetDefaultValue

func (a *Argument) SetDefaultValue(value string) *Argument

func (*Argument) SetName

func (a *Argument) SetName(name string) *Argument

func (*Argument) SetOption

func (a *Argument) SetOption(o *Option) *Argument

func (*Argument) SetValidation

func (a *Argument) SetValidation(callable validationFunc, message *string) *Argument

func (*Argument) SetValue

func (a *Argument) SetValue(value ...string) (*Argument, error)

func (*Argument) Validates

func (a *Argument) Validates(args ...string) bool

type Arguments

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

func NewArguments

func NewArguments(arguments []string) *Arguments

func (*Arguments) FromString

func (a *Arguments) FromString(argsString string) *Arguments

func (*Arguments) Process

func (a *Arguments) Process(getopt *GetOpt, setOption setOptionFunc, setCommand setCommandFunc, addOperand addOperandFunc) (bool, error)

func (*Arguments) Value

func (a *Arguments) Value(arg string, name string) string

type Command

type Command struct {
	WithOptions
	WithOperands
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(name string, handler handlerFunc, options ...*Option) (*Command, error)

func (*Command) Build

func (c *Command) Build(name string, handler handlerFunc, options ...*Option) (*Command, error)

func (*Command) Description

func (c *Command) Description() string

func (*Command) GetDescription

func (c *Command) GetDescription() string

func (*Command) GetHandler

func (c *Command) GetHandler() handlerFunc

func (*Command) GetName

func (c *Command) GetName() string

func (*Command) GetShortDescription

func (c *Command) GetShortDescription() string

func (*Command) Name

func (c *Command) Name() string

func (*Command) SetDescription

func (c *Command) SetDescription(longDescription string) *Command

func (*Command) SetHandler

func (c *Command) SetHandler(handler handlerFunc) *Command

func (*Command) SetName

func (c *Command) SetName(name string) (*Command, error)

func (*Command) ShortDescription

func (c *Command) ShortDescription() string

type CommandInterface

type CommandInterface interface {
	GetHandler() handlerFunc
	GetName() string
	GetOptions() []*Option
	GetOperands() []*Operand
	GetDescription() string
	GetShortDescription() string
	SetName(string) (*Command, error)
	SetHandler(handlerFunc) *Command
	SetDescription(string) *Command
}

type Describable

type Describable interface {
	Describe() string
}

type GetOpt

type GetOpt struct {
	WithOperands
	WithOptions
	// contains filtered or unexported fields
}

func NewGetOpt

func NewGetOpt(options string, settings map[string]string) (*GetOpt, error)

func (*GetOpt) AddCommand

func (g *GetOpt) AddCommand(command CommandInterface) (*GetOpt, error)

func (*GetOpt) AddCommands

func (g *GetOpt) AddCommands(commands ...CommandInterface) (*GetOpt, error)

func (*GetOpt) Count

func (g *GetOpt) Count() int

func (*GetOpt) Get

func (g *GetOpt) Get(setting string) string

func (*GetOpt) GetCommand

func (g *GetOpt) GetCommand(name string) CommandInterface

func (*GetOpt) GetCommands

func (g *GetOpt) GetCommands() map[string]CommandInterface

func (*GetOpt) GetHelp

func (g *GetOpt) GetHelp() HelpInterface

func (*GetOpt) GetHelpText

func (g *GetOpt) GetHelpText(data map[string]string) string

func (*GetOpt) GetOperand

func (g *GetOpt) GetOperand(index string) []string

func (*GetOpt) GetOperands

func (g *GetOpt) GetOperands() []string

func (*GetOpt) GetOptionString

func (g *GetOpt) GetOptionString(name string) string

func (*GetOpt) GetOptionValue

func (g *GetOpt) GetOptionValue(name string) []string

func (*GetOpt) GetOptions

func (g *GetOpt) GetOptions() map[string][]string

func (*GetOpt) HasCommands

func (g *GetOpt) HasCommands() bool

func (*GetOpt) Iter

func (g *GetOpt) Iter() map[string][]string

func (*GetOpt) NextOperand

func (g *GetOpt) NextOperand() *Operand

func (*GetOpt) Parse

func (g *GetOpt) Parse(arguments string)

func (*GetOpt) Process

func (g *GetOpt) Process(args ...string) error

func (*GetOpt) Set

func (g *GetOpt) Set(setting string, value string) *GetOpt

func (*GetOpt) SetHelp

func (g *GetOpt) SetHelp(help HelpInterface) *GetOpt

func (*GetOpt) SetHelpLang

func (g *GetOpt) SetHelpLang(language string) bool

func (*GetOpt) SetLang

func (g *GetOpt) SetLang(language string) bool

func (*GetOpt) SetScriptName

func (g *GetOpt) SetScriptName(scriptName string) *GetOpt

type Help

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

func NewHelp

func NewHelp(settings map[string]string) *Help

func (*Help) GetCommandsTemplate

func (h *Help) GetCommandsTemplate() string

func (*Help) GetOptionsTemplate

func (h *Help) GetOptionsTemplate() string

func (*Help) GetText

func (h *Help) GetText(key string) string

func (*Help) GetUsageTemplate

func (h *Help) GetUsageTemplate() string

func (*Help) Render

func (h *Help) Render(getOpt *GetOpt, data map[string]string) string

func (*Help) Set

func (h *Help) Set(setting string, value string) *Help

func (*Help) SetCommandsTemplate

func (h *Help) SetCommandsTemplate(commandsTemplate string) *Help

func (*Help) SetOptionsTemplate

func (h *Help) SetOptionsTemplate(optionsTemplate string) *Help

func (*Help) SetTexts

func (h *Help) SetTexts(texts map[string]string) *Help

func (*Help) SetUsageTemplate

func (h *Help) SetUsageTemplate(usageTemplate string) *Help

type HelpInterface

type HelpInterface interface {
	Render(*GetOpt, map[string]string) string
}

type Operand

type Operand struct {
	Argument
	// contains filtered or unexported fields
}

func NewOperand

func NewOperand(name string, mode int) *Operand

func (*Operand) GetDescription

func (o *Operand) GetDescription() string

func (*Operand) GetValue

func (o *Operand) GetValue() []string

func (*Operand) IsRequired

func (o *Operand) IsRequired() bool

func (*Operand) Required

func (o *Operand) Required(required bool) *Operand

func (*Operand) SetDescription

func (o *Operand) SetDescription(description string) *Operand

func (*Operand) SetValue

func (o *Operand) SetValue(value ...string) (*Operand, error)

func (*Operand) String

func (o *Operand) String() string

func (*Operand) Value

func (o *Operand) Value() []string

type Option

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

func NewOption

func NewOption(short rune, long string, mode string, description ...string) (*Option, error)

func (*Option) Describe

func (o *Option) Describe() string

func (*Option) GetArgument

func (o *Option) GetArgument() *Argument

func (*Option) GetDescription

func (o *Option) GetDescription() string

func (*Option) GetLong

func (o *Option) GetLong() string

func (*Option) GetMode

func (o *Option) GetMode() string

func (*Option) GetName

func (o *Option) GetName() string

func (*Option) GetShort

func (o *Option) GetShort() rune

func (*Option) GetValue

func (o *Option) GetValue() []string

func (*Option) Long

func (o *Option) Long() string

func (*Option) Mode

func (o *Option) Mode() string

func (*Option) SetArgument

func (o *Option) SetArgument(arg *Argument) (*Option, error)

func (*Option) SetArgumentName

func (o *Option) SetArgumentName(name string) *Option

func (*Option) SetDefaultValue

func (o *Option) SetDefaultValue(value string) *Option

func (*Option) SetDescription

func (o *Option) SetDescription(description string) *Option

func (*Option) SetLong

func (o *Option) SetLong(long string) (*Option, error)

func (*Option) SetMode

func (o *Option) SetMode(mode string) (*Option, error)

func (*Option) SetShort

func (o *Option) SetShort(short rune) (*Option, error)

func (*Option) SetValidation

func (o *Option) SetValidation(validation validationFunc, message *string) *Option

func (*Option) SetValue

func (o *Option) SetValue(value ...string) (*Option, error)

func (*Option) Short

func (o *Option) Short() rune

func (*Option) String

func (o *Option) String() string

func (*Option) Value

func (o *Option) Value() []string

type OptionParser

type OptionParser struct{}

func NewOptionParser

func NewOptionParser(mode string) *OptionParser

func (*OptionParser) CompleteOptionArray

func (o *OptionParser) CompleteOptionArray(row []string) []string

func (*OptionParser) ParseArray

func (o *OptionParser) ParseArray(p []string) (*Option, error)

func (*OptionParser) ParseString

func (o *OptionParser) ParseString(s string) ([]*Option, error)

type Translator

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

func GetTranslator

func GetTranslator() *Translator

func NewTranslator

func NewTranslator(language string, asFallback ...bool) (*Translator, error)

func (*Translator) LoadTranslations

func (t *Translator) LoadTranslations()

func (*Translator) SetLanguage

func (t *Translator) SetLanguage(language string) bool

func (*Translator) Translate

func (t *Translator) Translate(key string) string

type WithOperands

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

func (*WithOperands) AddOperand

func (w *WithOperands) AddOperand(operand *Operand) (*WithOperands, error)

func (*WithOperands) AddOperands

func (w *WithOperands) AddOperands(operands ...*Operand) (*WithOperands, error)

func (*WithOperands) GetOperand

func (w *WithOperands) GetOperand(index interface{}) *Operand

func (*WithOperands) GetOperands

func (w *WithOperands) GetOperands() []*Operand

func (*WithOperands) HasOperands

func (w *WithOperands) HasOperands() bool

type WithOptions

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

func (*WithOptions) AddOption

func (w *WithOptions) AddOption(option *Option) (*WithOptions, error)

func (*WithOptions) AddOptionArray

func (w *WithOptions) AddOptionArray(s []string) (*WithOptions, error)

func (*WithOptions) AddOptionString

func (w *WithOptions) AddOptionString(option string) (*WithOptions, error)

func (*WithOptions) AddOptions

func (w *WithOptions) AddOptions(options ...*Option) (*WithOptions, error)

func (*WithOptions) Conflicts

func (w *WithOptions) Conflicts(option *Option) bool

func (*WithOptions) GetOption

func (w *WithOptions) GetOption(name string) *Option

func (*WithOptions) GetOptions

func (w *WithOptions) GetOptions() []*Option

func (*WithOptions) HasOptions

func (w *WithOptions) HasOptions() bool

Directories

Path Synopsis
Package errors implements functions to manipulate errors.
Package errors implements functions to manipulate errors.

Jump to

Keyboard shortcuts

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