eflag

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT, MIT Imports: 6 Imported by: 2

README

eflag

-- import "github.com/cmcoffee/go-snuglib/eflag"

Package 'eflag' is a wrapper around Go's standard flag, it provides enhancments for: Adding Header's and Footer's to Usage. Adding Aliases to flags. (ie.. -d, --debug) Enhances formatting for flag usage. Aside from that everything else is standard from the flag library.

Usage

var (
	CLIArgs       = cmd.CLIArgs
	SyntaxName    = cmd.SyntaxName
	SetOutput     = cmd.SetOutput
	PrintDefaults = cmd.PrintDefaults
	Shorten       = cmd.Shorten
	String        = cmd.String
	StringVar     = cmd.StringVar
	Arg           = cmd.Arg
	Args          = cmd.Args
	Bool          = cmd.Bool
	BoolVar       = cmd.BoolVar
	Duration      = cmd.Duration
	DurationVar   = cmd.DurationVar
	Float64       = cmd.Float64
	Float64Var    = cmd.Float64Var
	Int           = cmd.Int
	IntVar        = cmd.IntVar
	Int64         = cmd.Int64
	Int64Var      = cmd.Int64Var
	Lookup        = cmd.Lookup
	Multi         = cmd.Multi
	MultiVar      = cmd.MultiVar
	NArg          = cmd.NArg
	NFlag         = cmd.NFlag
	Name          = cmd.Name
	Output        = cmd.Output
	Parsed        = cmd.Parsed
	Uint          = cmd.Uint
	UintVar       = cmd.UintVar
	Uint64        = cmd.Uint64
	Uint64Var     = cmd.Uint64Var
	Var           = cmd.Var
	Visit         = cmd.Visit
	VisitAll      = cmd.VisitAll
)
var ErrHelp = flag.ErrHelp
func Footer(input string)

Sets the footer for usage info.

func Header
func Header(input string)

Sets the header for usage info.

func Parse
func Parse() (err error)

Parse flags

func Usage
func Usage()

Shows usage.

type EFlagSet
type EFlagSet struct {
	Header     string // Header presented at start of help.
	Footer     string // Footer presented at end of help.
	AdaptArgs  bool   // Reorders flags and arguments so flags come first, non-flag arguments second, unescapes arguments with '\' escape character.
	ShowSyntax bool   // Display Usage: line, CLIArgs will automatically display usage info.

	*flag.FlagSet
}

A EFlagSet is a set of defined flags.

func NewFlagSet
func NewFlagSet(name string, errorHandling ErrorHandling) (output *EFlagSet)

Load a flag created with flag package.

func (*EFlagSet) Args
func (s *EFlagSet) Args() []string

Returns extra arguments.

func (*EFlagSet) Bool
func (E *EFlagSet) Bool(name string, usage string) *bool

Bool defines a bool flag with specified name, default and usage string. The return value is the address of a bool variable that stores the value of the flag.

func (*EFlagSet) BoolVar
func (E *EFlagSet) BoolVar(p *bool, name string, usage string)

BoolVar defines a bool flag with specified name, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func (*EFlagSet) CLIArgs
func (E *EFlagSet) CLIArgs(name ...string)

Maps CLI Args not set to flags, to flags in order of addition.

func (*EFlagSet) IsSet
func (s *EFlagSet) IsSet(name string) bool
func (*EFlagSet) Multi
func (E *EFlagSet) Multi(name string, value string, usage string) *[]string

Array variable, ie.. comma-separated values --flag="test","test2"

func (*EFlagSet) MultiVar
func (E *EFlagSet) MultiVar(p *[]string, name string, value string, usage string)

Array variable, ie.. comma-separated values --flag="test","test2"

func (*EFlagSet) Order
func (s *EFlagSet) Order(name ...string)

Specifies the order in which flags are displayed.

func (*EFlagSet) Parse
func (s *EFlagSet) Parse(args []string) (err error)

Wraps around the standard flag Parse, adds header and footer.

func (*EFlagSet) PrintDefaults
func (s *EFlagSet) PrintDefaults()

Reads through all flags available and outputs with better formatting.

func (*EFlagSet) ResolveAlias
func (s *EFlagSet) ResolveAlias(name string) string

Resolves Alias name to fullname

func (*EFlagSet) SetOutput
func (s *EFlagSet) SetOutput(output io.Writer)

Change where output will be directed.

func (*EFlagSet) Shorten
func (s *EFlagSet) Shorten(name string, ch rune)

Adds a single charachter alias to the command, ie.. --help h

func (*EFlagSet) SyntaxName
func (E *EFlagSet) SyntaxName(name string)

Specifies the name that will be shown for the usage/syntax.

func (*EFlagSet) VisitAll
func (s *EFlagSet) VisitAll(fn func(*Flag))

Provide same order.

type ErrorHandling
type ErrorHandling int

Duplicate flag's ErrorHandling.

const (
	ContinueOnError ErrorHandling = iota
	ExitOnError
	PanicOnError
	ReturnErrorOnly
)
type Flag
type Flag = flag.Flag

Documentation

Overview

Package 'eflag' is a wrapper around Go's standard flag, it provides enhancments for: Adding Header's and Footer's to Usage. Adding Aliases to flags. (ie.. -d, --debug) Enhances formatting for flag usage. Aside from that everything else is standard from the flag library.

Index

Constants

This section is empty.

Variables

View Source
var (
	CLIArgs       = cmd.CLIArgs
	SyntaxName    = cmd.SyntaxName
	SetOutput     = cmd.SetOutput
	PrintDefaults = cmd.PrintDefaults
	Shorten       = cmd.Shorten
	String        = cmd.String
	StringVar     = cmd.StringVar
	Arg           = cmd.Arg
	Args          = cmd.Args
	Bool          = cmd.Bool
	BoolVar       = cmd.BoolVar
	Duration      = cmd.Duration
	DurationVar   = cmd.DurationVar
	Float64       = cmd.Float64
	Float64Var    = cmd.Float64Var
	Int           = cmd.Int
	IntVar        = cmd.IntVar
	Int64         = cmd.Int64
	Int64Var      = cmd.Int64Var
	Lookup        = cmd.Lookup
	Multi         = cmd.Multi
	MultiVar      = cmd.MultiVar
	NArg          = cmd.NArg
	NFlag         = cmd.NFlag
	Name          = cmd.Name
	Output        = cmd.Output
	Parsed        = cmd.Parsed
	Uint          = cmd.Uint
	UintVar       = cmd.UintVar
	Uint64        = cmd.Uint64
	Uint64Var     = cmd.Uint64Var
	Var           = cmd.Var
	Visit         = cmd.Visit
	VisitAll      = cmd.VisitAll
)
View Source
var ErrHelp = flag.ErrHelp

Functions

func Footer(input string)

Sets the footer for usage info.

func Header(input string)

Sets the header for usage info.

func Parse

func Parse() (err error)

Parse flags

func Usage

func Usage()

Shows usage.

Types

type EFlagSet

type EFlagSet struct {
	Header     string // Header presented at start of help.
	Footer     string // Footer presented at end of help.
	AdaptArgs  bool   // Reorders flags and arguments so flags come first, non-flag arguments second, unescapes arguments with '\' escape character.
	ShowSyntax bool   // Display Usage: line, CLIArgs will automatically display usage info.

	*flag.FlagSet
	// contains filtered or unexported fields
}

A EFlagSet is a set of defined flags.

func NewFlagSet

func NewFlagSet(name string, errorHandling ErrorHandling) (output *EFlagSet)

Load a flag created with flag package.

func (*EFlagSet) Args added in v1.0.2

func (s *EFlagSet) Args() []string

Returns extra arguments.

func (*EFlagSet) Bool added in v1.0.10

func (E *EFlagSet) Bool(name string, usage string) *bool

Bool defines a bool flag with specified name, default and usage string. The return value is the address of a bool variable that stores the value of the flag.

func (*EFlagSet) BoolVar added in v1.0.10

func (E *EFlagSet) BoolVar(p *bool, name string, usage string)

BoolVar defines a bool flag with specified name, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func (*EFlagSet) CLIArgs added in v1.0.10

func (E *EFlagSet) CLIArgs(name ...string)

Maps CLI Args not set to flags, to flags in order of addition.

func (*EFlagSet) IsSet

func (s *EFlagSet) IsSet(name string) bool

func (*EFlagSet) Multi added in v1.0.8

func (E *EFlagSet) Multi(name string, value string, usage string) *[]string

Array variable, ie.. comma-separated values --flag="test","test2"

func (*EFlagSet) MultiVar added in v1.0.8

func (E *EFlagSet) MultiVar(p *[]string, name string, value string, usage string)

Array variable, ie.. comma-separated values --flag="test","test2"

func (*EFlagSet) Order

func (s *EFlagSet) Order(name ...string)

Specifies the order in which flags are displayed.

func (*EFlagSet) Parse

func (s *EFlagSet) Parse(args []string) (err error)

Wraps around the standard flag Parse, adds header and footer.

func (*EFlagSet) PrintDefaults

func (s *EFlagSet) PrintDefaults()

Reads through all flags available and outputs with better formatting.

func (*EFlagSet) ResolveAlias added in v1.0.2

func (s *EFlagSet) ResolveAlias(name string) string

Resolves Alias name to fullname

func (*EFlagSet) SetOutput

func (s *EFlagSet) SetOutput(output io.Writer)

Change where output will be directed.

func (*EFlagSet) Shorten added in v1.0.11

func (s *EFlagSet) Shorten(name string, ch rune)

Adds a single charachter alias to the command, ie.. --help h

func (*EFlagSet) SyntaxName added in v1.0.10

func (E *EFlagSet) SyntaxName(name string)

Specifies the name that will be shown for the usage/syntax.

func (*EFlagSet) VisitAll added in v1.0.13

func (s *EFlagSet) VisitAll(fn func(*Flag))

Provide same order.

type ErrorHandling

type ErrorHandling int

Duplicate flag's ErrorHandling.

const (
	ContinueOnError ErrorHandling = iota
	ExitOnError
	PanicOnError
	ReturnErrorOnly
)

type Flag added in v1.0.2

type Flag = flag.Flag

Jump to

Keyboard shortcuts

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