cliparser

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: BSD-2-Clause-Views Imports: 2 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cliparser provides a simple parsing API for CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	Type ComponentType

	Name string
	Arg  string
}

Component is a resultant type of this package.

func (Component) String

func (c Component) String() string

type ComponentType

type ComponentType int

ComponentType represents the type of parsed component.

const (
	// Unknown is not used in this package.
	Unknown ComponentType = iota
	// Option for -o -opt --opt
	Option
	// Command for command (requires call of Parser.HintCommand)
	Command
	// Arg is not an option nor a command.
	Arg
)

func (ComponentType) String

func (t ComponentType) String() string

type Parser

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

Parser contains parsing configurations and methods.

func New

func New() Parser

New makes a Parser.

func (*Parser) Feed

func (p *Parser) Feed(args []string)

Feed is called when you pass os.Args. On next step, call Parser.Parse.

func (*Parser) GetComponent

func (p *Parser) GetComponent() *Component

GetComponent returns a Component. At end of source stream, this returns nil.

func (*Parser) HintAlias

func (p *Parser) HintAlias(alias, name string, optNS ...[]string)

HintAlias is for defining another name.

func (*Parser) HintCommand

func (p *Parser) HintCommand(name string, optNS ...[]string)

HintCommand is for giving the parser hint that the name is command.

func (*Parser) HintDisableDoubleHyphen added in v0.2.0

func (p *Parser) HintDisableDoubleHyphen()

HintDisableDoubleHyphen disallows -abc -> -a -b -c

func (*Parser) HintLongName

func (p *Parser) HintLongName(name string, optNS ...[]string)

HintLongName is for giving the parser hint that the name is option has a long name even if ONE-HYPHEND (-hoge)

func (*Parser) HintNoOptionsGrouped

func (p *Parser) HintNoOptionsGrouped()

HintNoOptionsGrouped disallows -abc -> -a -b -c

func (*Parser) HintWithArg

func (p *Parser) HintWithArg(name string, optNS ...[]string)

HintWithArg is for giving the parser hint that the name is option and it requires an argument.

func (*Parser) Parse

func (p *Parser) Parse() error

Parse parses given (at Parser.Feed) command line string. Call Parser.GetComponent-s serially to get results.

func (*Parser) Reset

func (p *Parser) Reset()

Reset resets its parsing results, except hints. Next, call Feed and Parse.

Jump to

Keyboard shortcuts

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