parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package parser implements command arguments parsing.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgNum = errors.New("ERR wrong number of arguments")
	ErrInvalidFloat  = errors.New("ERR value is not a float")
	ErrInvalidInt    = errors.New("ERR value is not an integer")
	ErrSyntaxError   = errors.New("ERR syntax error")
)

Functions

This section is empty.

Types

type ParserFunc

type ParserFunc func(args [][]byte) (bool, [][]byte, error)

ParserFunc parses some of the arguments and returns the rest.

func AnyMap

func AnyMap(dest *map[string]any) ParserFunc

AnyMap parses variadic name-value pairs.

func Anys

func Anys(dest *[]any) ParserFunc

Anys parses variadic arguments as a slice of any.

func Bytes

func Bytes(dest *[]byte) ParserFunc

Bytes parses a positional argument as a byte slice.

func Enum

func Enum(dest *string, allowed ...string) ParserFunc

Enum parses a positional argument as a string enum.

func Flag

func Flag(name string, dest *bool) ParserFunc

Flag parses a named argument as a bool.

func Float

func Float(dest *float64) ParserFunc

Float parses a positional argument as an float.

func FloatMap

func FloatMap(dest *map[any]float64) ParserFunc

FloatMap parses variadic float-value pairs.

func Int

func Int(dest *int) ParserFunc

Int parses a positional argument as an integer.

func Named

func Named(name string, parsers ...ParserFunc) ParserFunc

Named parses a named argument with given parsers. Returns an error if any of the parsers does not fire.

func OneOf

func OneOf(parsers ...ParserFunc) ParserFunc

OneOf parses the arguments with one of the given parsers. Returns an error if more than one parser fires.

func String

func String(dest *string) ParserFunc

String parses a positional argument as a string.

func Strings

func Strings(dest *[]string) ParserFunc

Strings parses variadic arguments as a slice of strings.

func StringsN

func StringsN(dest *[]string, nVar *int) ParserFunc

StringsN parses n variadic arguments as a slice of strings. nVar is a pointer to the number of arguments to parse.

type Pipeline

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

Pipeline parses command arguments according to a sequence of parsers.

func New

func New(parsers ...ParserFunc) *Pipeline

New creates a new pipeline with the given parsers.

func (*Pipeline) Required

func (p *Pipeline) Required(n int) *Pipeline

Required sets the number of required positional arguments.

func (*Pipeline) Run

func (p *Pipeline) Run(args [][]byte) error

Run parses the arguments according to the pipeline.

Jump to

Keyboard shortcuts

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