argo

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT, 0BSD Imports: 6 Imported by: 0

README

Argo

A simple Go library for parsing command line arguments.

Documentation

Overview

Package argo is a library for parsing command line arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgParser

type ArgParser struct {
	// Help text for the application or command.
	Helptext string

	// The application's version number.
	Version string

	// Stores positional arguments.
	Args []string

	// Stores the callback function for a command parser.
	Callback func(string, *ArgParser)
	// contains filtered or unexported fields
}

An ArgParser instance stores registered options and commands.

func NewParser

func NewParser() *ArgParser

NewParser initializes a new ArgParser instance.

func (*ArgParser) ArgsAsFloats

func (parser *ArgParser) ArgsAsFloats() []float64

ArgsAsFloats attempts to parse and return the positional arguments as a slice of floats. Exits with an error message if any of the arguments cannot be parsed as a float.

func (*ArgParser) ArgsAsInts

func (parser *ArgParser) ArgsAsInts() []int

ArgsAsInts attempts to parse and return the positional arguments as a slice of integers. Exits with an error message if any of the arguments cannot be parsed as an integer.

func (*ArgParser) CommandName

func (parser *ArgParser) CommandName() string

CommandName returns the command name, if the parser has found a command.

func (*ArgParser) CommandParser

func (parser *ArgParser) CommandParser() *ArgParser

CommandParser returns the command's parser instance, if the parser has found a command.

func (*ArgParser) Count

func (parser *ArgParser) Count(name string) int

Count returns the number of times the specified option was found.

func (*ArgParser) CountArgs

func (parser *ArgParser) CountArgs() int

CountArgs returns the number of positional arguments.

func (*ArgParser) EnableHelpCommand

func (parser *ArgParser) EnableHelpCommand(enable bool)

This boolean switch toggles support for an automatic `help` command which prints subcommand helptext. The value defaults to `false` but gets toggled automatically to true whenever a command is registered. You can use this method to disable the feature if required.

func (*ArgParser) ExitWithHelptext

func (parser *ArgParser) ExitWithHelptext()

ExitWithHelptext prints the parser's help text, then exits.

func (*ArgParser) ExitWithVersion

func (parser *ArgParser) ExitWithVersion()

ExitWithVersion prints the parser's version string, then exits.

func (*ArgParser) FloatValue

func (parser *ArgParser) FloatValue(name string) float64

FloatValue returns the value of the specified float-valued option.

func (*ArgParser) FloatValues

func (parser *ArgParser) FloatValues(name string) []float64

FloatValues returns the specified float-valued option's list of values.

func (*ArgParser) Found

func (parser *ArgParser) Found(name string) bool

Found returns true if the specified option was found.

func (*ArgParser) HasArgs

func (parser *ArgParser) HasArgs() bool

HasArgs returns true if the parser has found one or more positional arguments.

func (*ArgParser) HasCommand

func (parser *ArgParser) HasCommand() bool

HasCommand returns true if the parser has found a command.

func (*ArgParser) IntValue

func (parser *ArgParser) IntValue(name string) int

IntValue returns the value of the specified integer-valued option.

func (*ArgParser) IntValues

func (parser *ArgParser) IntValues(name string) []int

IntValues returns the specified integer-valued option's list of values.

func (*ArgParser) NewCommand

func (parser *ArgParser) NewCommand(name string) *ArgParser

NewCommand registers a new command. The `name` parameter accepts an unlimited number of space- separated aliases for the command. Returns the command's `ArgParser` instance.

func (*ArgParser) NewFlag

func (parser *ArgParser) NewFlag(name string)

NewFlag registers a new flag. The `name` parameter accepts an unlimited number of space-separated aliases and single-character shortcuts.

func (*ArgParser) NewFloatOption

func (parser *ArgParser) NewFloatOption(name string, fallback float64)

NewFloatOption registers a new float-valued option. The `name` parameter accepts an unlimited number of space-separated aliases and single-character shortcuts. The `fallback` parameter specifies the option's default value.

func (*ArgParser) NewIntOption

func (parser *ArgParser) NewIntOption(name string, fallback int)

NewIntOption registers a new integer-valued option. The `name` parameter accepts an unlimited number of space-separated aliases and single-character shortcuts. The `fallback` parameter specifies the option's default value.

func (*ArgParser) NewStringOption

func (parser *ArgParser) NewStringOption(name string, fallback string)

NewStringOption registers a new string-valued option. The `name` parameter accepts an unlimited number of space-separated aliases and single-character shortcuts. The `fallback` parameter specifies the option's default value.

func (*ArgParser) Parse

func (parser *ArgParser) Parse()

Parse parses the application's command line arguments.

func (*ArgParser) ParseArgs

func (parser *ArgParser) ParseArgs(args []string)

ParseArgs parses a slice of string arguments.

func (*ArgParser) String

func (parser *ArgParser) String() string

String returns a string representation of the parser instance.

func (*ArgParser) StringValue

func (parser *ArgParser) StringValue(name string) string

StringValue returns the value of the specified string-valued option.

func (*ArgParser) StringValues

func (parser *ArgParser) StringValues(name string) []string

StringValues returns the specified string-valued option's list of values.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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