args

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: MIT Imports: 3 Imported by: 2

README

args-parser

GoDoc

Simple arguments parser written in Go. Mainly here so I can easily use it in my other projects.

You can currently register options/flags, then check on if that flag was used and access it's value if applicable.

Auto-generated usage information.

Flags follow the UNIX rules of having one dash for single letter versions of flags and double dashed versions of flags with whole words. (e.g. -a --all)

Argument values proceed the flag with a = sign separating (e.g. -a=value --arg=value)

Does not yet support subcommands.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Args map[string]string

Args is a map of the args that were passed after the first arg with dash prefixes (e.g. -- or -) trimmed. A value is set for a member of Args if an arg is proceeded with an equality operator (e.g. --arg=value).

View Source
var CustomUsage string

CustomUsage allows you to add custom usage details. The value of CustomUsage is printed in between the name of the binary and the flags in the usage message.

Functions

func PrintUsage

func PrintUsage()

PrintUsage prints a usage message based on the arguments and usage you have registered then exits.

func Register

func Register(arg Argument)

Register an Argument.

func Using

func Using(name string) bool

Using returns a boolean indicating if Argument name was passed to your executable.

func Value

func Value(name string) string

Value returns a string of the value of Argument name if passed to your executable.

Types

type Argument added in v1.1.0

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

Jump to

Keyboard shortcuts

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