antargs

package module
v0.0.0-...-3a9c5dc Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 3 Imported by: 0

README

antargs

An argument package for go.

This is a work in progress. Not usable at the moment.

Basic usage:

// setup
antArg, _ := New("myTestProgram", "myTestProgram is a very nice program!")
antArg.NewArg("--say", "What should I say?", false, "", 1)
antArg.NewArg("--style", "In what style should I say it?", false, "", 1)

// parse
antArg.Parse(os.Args)

// use
sayArg := antArg.findArgument("--say")
sayValue := arg.values[0]
styleValue := antArg.findArgument("--style").values[0]

if styleValue == "shout" {
    sayValue = ToUpper(sayValue)
}
fmt.Printf("I say: %s", sayValue)

terminal:

$ ./myTestProgram --say "You're A Wizard, Harry!" --style shout
$ I say: YOU'RE A WIZARD, HARRY!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowOnlyOneTopLevelArgument

func AllowOnlyOneTopLevelArgument() parseOption

func AllowTopLevelArgumentWithoutName

func AllowTopLevelArgumentWithoutName() parseOption

func DontRemoveFirstArgument

func DontRemoveFirstArgument() parseOption

func RequireAtleastOneTopLevelArgument

func RequireAtleastOneTopLevelArgument() parseOption

Types

type AntArg

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

AntArg is the main struct when working with AntArg package. It contains an array of arguments of the using program, as well as information about the program.

func New

func New(name string, help string) (*AntArg, error)

New initializes an instance of AntArgs, should be used for creating the main program AntArg instance

func (AntArg) Equal

func (a AntArg) Equal(b AntArg) bool

Equal compares two AntArg objects and decied if they are equal

func (*AntArg) NewArg

func (antArg *AntArg) NewArg(name string, help string, isFlag bool, shortcut string, numberOfValues int) (*Arg, error)

NewArg initializes a new argument tied to a parent AntArg

func (*AntArg) Parse

func (antArg *AntArg) Parse(arguments []string, parseOptions ...parseOption) error

Parse takes an array of string arguments assigns the arguments to their corresponding value in the AntArg object.

parseOptions can be provided to control the parsing: AllowOnlyOneTopLevelArgument() = Will return error if more than 1 argument is provided at the top level (AntArg.args) DontRemoveFirstArgument() = Will disable the default behavior to remove the first element of the argument array RequireAtleastOneTopLevelArgument() = Will return error if no argument has been provided AllowTopLevelArgumentWithoutName() = Will allow the top level arguments to be provided with only values, this will assume no top level argument is provided with name, and that the values are provided in the order that the arguments was provided into the AntArgs object

The following errors can be returned: "No argument supplied" = Will happen if RequireOneTopLevelArgument parseOption was requested and no argument was provided "%s it not a valid argument" = Will happen if a top level argument was supplied but no corresponding argument was declared in the AntAr "Only one top level argument is allowed" == Will happening if more than 1 top level argument was provided and the parseOption AllowonlyOneTopLevelArgument was request

func (AntArg) Prettify

func (antArg AntArg) Prettify() string

Prettify returns an JSON object as a string representing the AntArg

func (AntArg) PrintArgumentInformation

func (antArg AntArg) PrintArgumentInformation()

type Arg

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

Arg is the struct containing a specific argument for an AntArg list of arguments

func (*Arg) NewSubArg

func (arg *Arg) NewSubArg(name string, help string, isFlag bool, shortcut string, numberOfValues int) (*Arg, error)

NewSubArg initializes a new argument tied to a parent arg

func (Arg) PrintSubArgumentInformation

func (arg Arg) PrintSubArgumentInformation()

Jump to

Keyboard shortcuts

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