Documentation
¶
Overview ¶
Package 'eflag' is a wrapper around Go's standard flag, it provides enhancments for: Adding Header 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 ¶
- Variables
- func Footer(input string)
- func Header(input string)
- func Parse() (err error)
- func Usage()
- type EFlagSet
- func (s *EFlagSet) Args() []string
- func (E *EFlagSet) Bool(name string, usage string) *bool
- func (E *EFlagSet) BoolVar(p *bool, name string, usage string)
- func (E *EFlagSet) InlineArgs(name ...string)
- func (s *EFlagSet) IsSet(name string) bool
- func (E *EFlagSet) Multi(name string, value string, usage string) *[]string
- func (E *EFlagSet) MultiVar(p *[]string, name string, value string, usage string)
- func (s *EFlagSet) Order(name ...string)
- func (s *EFlagSet) Parse(args []string) (err error)
- func (s *EFlagSet) PrintDefaults()
- func (s *EFlagSet) ResolveAlias(name string) string
- func (s *EFlagSet) SetOutput(output io.Writer)
- func (s *EFlagSet) Shorten(name string, ch rune)
- func (E *EFlagSet) SyntaxName(name string)
- func (s *EFlagSet) VisitAll(fn func(*Flag))
- type ErrorHandling
- type Flag
Constants ¶
This section is empty.
Variables ¶
var ( InlineArgs = cmd.InlineArgs 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
ErrHelp is returned by Parse when the -help flag is encountered.
Functions ¶
func Footer ¶
func Footer(input string)
Footer sets the footer message for the command line interface. It updates the 'Footer' field of the global 'cmd' flag set.
Types ¶
type EFlagSet ¶
type EFlagSet struct {
Header string // Header presented at start 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, InlineArgs will automatically display usage info.
*flag.FlagSet
// contains filtered or unexported fields
}
EFlagSet represents a flag set with extended features. It provides functionalities for customizing flag parsing, handling arguments, and generating help messages.
func NewFlagSet ¶
func NewFlagSet(name string, errorHandling ErrorHandling) (output *EFlagSet)
NewFlagSet creates a new flag set with the given name and error handling policy. It initializes the flag set and sets up the usage function.
func (*EFlagSet) Args ¶
Args returns the non-flag arguments. It adapts the arguments by removing the escape character '\' if AdaptArgs is true.
func (*EFlagSet) Bool ¶
Bool defines a boolean flag with the given name and usage string. It returns a pointer to the boolean value.
func (*EFlagSet) BoolVar ¶
BoolVar defines a boolean flag with the given name and usage string. It sets the default value of the flag to false if it is not set.
func (*EFlagSet) InlineArgs ¶
InlineArgs adds the specified flags to the argument map. It retrieves flags by name and appends them to E.argMap.
func (*EFlagSet) Multi ¶
Multi defines a multi-valued flag with the given name, initial value, and usage string.
func (*EFlagSet) MultiVar ¶
MultiVar defines a multi-valued flag with the given name, initial value, and usage string.
func (*EFlagSet) Order ¶
Order sets the order in which flags are processed. It takes a variable number of flag names as input.
func (*EFlagSet) PrintDefaults ¶
func (s *EFlagSet) PrintDefaults()
PrintDefaults prints the default values and usage information for all defined flags. It formats the output in a human-readable format, including aliases and default values.
func (*EFlagSet) ResolveAlias ¶
ResolveAlias resolves an alias for a given flag name. It returns the original name if no alias is found.
func (*EFlagSet) Shorten ¶
Shorten creates a short alias for a long flag name. It registers the alias in the flag set and creates a reverse lookup.
func (*EFlagSet) SyntaxName ¶
SyntaxName sets the syntax name for the flag set.
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling defines how errors are handled during flag parsing. It allows control over whether parsing continues after an error or if it stops immediately.
const ( ContinueOnError ErrorHandling = iota ExitOnError PanicOnError ReturnErrorOnly )
ErrorHandling defines strategies for handling errors. ContinueOnError continues execution after an error. ExitOnError terminates the program on error. PanicOnError causes a panic on error. ReturnErrorOnly returns the error without further action.