parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Overview

Package parser implements compatibility with the "github.com/jessevdk/go-flags" package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFlags

func AllFlags[T any]() []meta.Flag

AllFlags is a convenience method to get all flags for the provided argument type

func AllPositionals

func AllPositionals[T any]() []meta.Positional

func IsHelp

func IsHelp(err error) bool

IsHelp checks if err represents the help flag being passed

func IsUnknownFlag

func IsUnknownFlag(err error) bool

IsUnknownFlag checks if err indicates an unknown flag

func NewFlag

func NewFlag(option *flags.Option) (flag meta.Flag)

NewFlag creates a new flag based on an option from the flags package.

func NewPositional

func NewPositional(arg *flags.Arg, field reflect.StructField) (pos meta.Positional)

NewPositional creates a new Positional from a flag argument

Types

type Config

type Config struct {
	// IncludeUnknown causes unknown flags to be parsed as positional arguments.
	// When IncludeUnknown in false, unknown flags produce an error instead.
	IncludeUnknown bool
}

Config represents configuration for the parser for a command

func (Config) NewCommandParser

func (cfg Config) NewCommandParser(command any) (p Parser)

NewCommandParser checks if command represents a valid command and, when this is the case, creates a new parser for it with the config provided in ParserConfig.

type Parser

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

Parse represents a parser for arguments.

It is internally backed by the "github.com/jessevdk/go-flags" package.

func NewArgumentsParser

func NewArgumentsParser(args any) Parser

NewArgumentsParser creates a new parser fo parse a set of arguments

func (Parser) Flags

func (p Parser) Flags() []meta.Flag

Flags returns information about the flags belonging to this parser

func (Parser) ParseArgs

func (p Parser) ParseArgs(args []string) ([]string, error)

ParseArgs parses arguments for this parser.

The returned error may be nil, a help error, an unknown flag error or otherwise. See also IsHelp, IsUnknownFlag.

func (Parser) Positionals

func (p Parser) Positionals() []meta.Positional

Jump to

Keyboard shortcuts

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