gargsxd

package module
v0.0.0-...-fbc0e74 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: ISC Imports: 5 Imported by: 1

README

gargsxd

Similar to rargsxd!

Alternative argument parsing to the flag library.

Benefits

The main benefit for most people is the better help dialog:

help

Example

Example usage can be seen in morg

Documentation

Overview

Package gargsxd provides an argument type and parser similar to rargsxd (codeberg.org/BubbyRoosh/rargsxd) to use as an alternative to the flag library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Argv0

func Argv0() string

Returns os.Args[0] for setting ArgParser.Name

func Usage

func Usage() string

Returns a default Usage string for setting ArgParser.Usage

Types

type Arg

type Arg struct {
	// Help contains the message that will be printed for the argument when
	// PrintHelp is called.
	Help string
	// Short is the rune that is used when the argument is passed with `-`.
	Short rune
	// Long is the string that is used when the argument is passed with `--`.
	Long string
	// Value is the "generic" type for the value of the argument. When proper
	// generics are fully implemented and official/stable, interface{} will be
	// replaced.
	Value interface{}
}

Struct Arg is the base argument type that will hold the information for each argument along with its Value.

func Bool

func Bool(short rune, long string, def bool, help string) Arg

Bool is a helper function to return an argument with a bool value.

func Int

func Int(short rune, long string, def int, help string) Arg

Int is a helper function to return an argument with an int value.

func String

func String(short rune, long string, help string) Arg

String is a helper function to return an argument with a string value.

type ArgParser

type ArgParser struct {
	// Name is the name of the program (automatically set by passing Argv0()).
	Name string
	// Author is the name of the program's author(s).
	Author string
	// Version is the stringified version of the program.
	Version string
	// Copyright is the copyright string for the program (as some licenses
	// require something like "copyright (c) year name" somewhere in their
	// program)
	Copyright string
	// Info is a small description of the program.
	Info string
	// Usage is the command-line usage of the program. All occurrences of
	// "{name}" are replaced by Name. (Can be automatically set by using
	// Usage())
	Usage string
	// Args holds the arguments that will be parsed, and can be set/accessed by
	// their map name string.
	Args map[string]Arg
	// Extra holds any extra arguments that were not parsed with `-` or `--` or
	// were a value of one.
	Extra []string

	// Writer is the writer for where the output should be printed (for the
	// help menu). It will default to os.Stdout.
	Writer io.Writer
}

Struct ArgParser is the main parser holding information about the program and its arguments.

func (*ArgParser) Parse

func (ap *ArgParser) Parse() bool

Parse calls ParseSlice on os.Args[1:].

func (*ArgParser) ParseSlice

func (ap *ArgParser) ParseSlice(args []string) bool

ParseSlice parses `args`, returning whether or not the parsing had errors.

func (ArgParser) PrintHelp

func (ap ArgParser) PrintHelp()

PrintHelp prints a pre-formatted help message for the program. Because the arguments are stored as a map, their order may be different between runs of the program, since maps are unordered.

Jump to

Keyboard shortcuts

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