argparse

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

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

Go to latest
Published: Aug 1, 2020 License: GPL-3.0 Imports: 6 Imported by: 14

Documentation

Index

Constants

View Source
const (
	ParamIdentifierPrefix = ":"
	// TODO: Should it be a public constant here? Other options? Package-private?
	AllTasks string = ParamIdentifierPrefix + "all"
)

Variables

This section is empty.

Functions

func GetTaskNames

func GetTaskNames(taskField string) ([]string, error)

Split task names given as a comma-separated field, check for validity.

func SingleQuantity

func SingleQuantity(t string, elems ...string) []msg.Quantity

func WarnUnused

func WarnUnused(args []string)

Warn the user about arguments being unevaluated. If args is empty, no warning is issued.

Types

type ArgHandler

type ArgHandler interface {
	// Parse the params and modify cmd accordingly.
	// Returns unused arguments and a possible error.
	HandleArgs(cmd *msg.Cmd, args []string) ([]string, error)
	// Whether the argument handler takes any parameters.
	TakesParameters() bool
	// Describe available parameters
	DescribeParameters() []ParamDescription
}

func HandlerForParams

func HandlerForParams(params []Param) ArgHandler

type Description

type Description struct {
	Cmd    string // Name of the command
	First  string // The first class of arguments, if any
	Second string // The second class of arguments, if any
	What   string // What the command does
}

type Param

type Param struct {
	Name        string
	RequiresArg bool
	Quantifier  Quantifier
	Description string
}

func (Param) Describe

func (p Param) Describe() ParamDescription

type ParamDescription

type ParamDescription struct {
	ParamName        string // Name of the parameter
	ParamValues      string // Description of possible values
	ParamExplanation string // Explanation of this parameter
}

type Parser

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

TODO: Move methods to builder?

func CommandParser

func CommandParser(command string) *Parser

func (*Parser) Describe

func (p *Parser) Describe(what string) Description

func (*Parser) ParamDescription

func (p *Parser) ParamDescription() []ParamDescription

func (*Parser) Parse

func (p *Parser) Parse(args []string) (msg.Cmd, error)

Parse the given arguments.

func (*Parser) TaskDescription

func (p *Parser) TaskDescription() string

func (*Parser) WithArgHandler

func (p *Parser) WithArgHandler(h ArgHandler) *Parser

func (*Parser) WithMultipleTasks

func (p *Parser) WithMultipleTasks() *Parser

func (*Parser) WithSingleTask

func (p *Parser) WithSingleTask() *Parser

func (*Parser) WithoutParams

func (p *Parser) WithoutParams() *Parser

func (*Parser) WithoutTask

func (p *Parser) WithoutTask() *Parser

type Quantifier

type Quantifier interface {
	Parse(str string) ([]msg.Quantity, error)
	DescribeUsage() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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