betterargs

package module
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: BSD-3-Clause Imports: 4 Imported by: ? modules, 0 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.

README

betterargs

Adds better argument handling for go projects

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteArguments

func ExecuteArguments(parsedArgs ParsedArguments)

Types

type Flag

type Flag struct {
	Description string

	// All possible flags that can trigger this option
	//  // for --help
	//  []string{"-H", "-?"}
	Aliases []string

	// All the inputs in the order to expect them in
	//
	// If, for example, the first input's validator returned false
	// and the input after it returned true,
	// the next arg will be evaluated by the third input
	Inputs InputOrder

	Action func(instance Instance)
}

func (Flag) String

func (this Flag) String() string

type Input

type Input struct {
	Name        string
	Description string

	// Is this input required to be present?
	//
	// If the input is not present after the flag, the program will panic and log an error specifying which input was expected
	Required bool

	// The maximum amount of times that this input can be repeated as long as the validator returns true foe each of them.
	//
	// 0 will be interperted as 1, this is to allow this field to be ommited.
	//
	// -1 for unlimeted
	MaxOccurences int

	// Specify a function that can validate a potential input.
	//
	// If ommited, the input will always be valid given that the arg is not a defined flag
	Validator func(arg string) bool
}

func (Input) String

func (this Input) String() string

type InputOrder

type InputOrder []Input

func (InputOrder) String

func (this InputOrder) String() string

type Instance

type Instance struct {
	// The index at which this instance occurred
	Index int
	// The arg that was used to trigger this instances definition
	Arg string
	// All the args that followed that are defined and validated to be inputs for this flag
	Inputs MInputInstances
}

func (Instance) String

func (this Instance) String() string

type MFlags

type MFlags map[string]Flag

A map of argument options that define all options for the current program

The key of the map will also be its default usage as an argument but with '--' infront of it

{ "flag-name": MFlags{...} }

func (MFlags) String

func (this MFlags) String() string

type MInputInstances

type MInputInstances map[string][]string

func (MInputInstances) String

func (this MInputInstances) String() string

type MInstances

type MInstances map[string][]Instance

All arg instances grouped by their arg definition key

func (MInstances) String

func (this MInstances) String() string

type ParsedArguments

type ParsedArguments struct {
	//TODO Find better wording for this comment:
	// The unedited arguments as they were passed in at the launch of the program
	Raw []string

	// The path to the file that is currently running.
	SourceFile string

	// The definitions of all possible argument flags and their implimentations
	Definitions MFlags

	// All arg instances that were present
	Args MInstances
}

func ParseArguments

func ParseArguments(args []string, definitions MFlags) (parsed ParsedArguments)

func (ParsedArguments) String

func (this ParsedArguments) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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