goflags

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 16 Imported by: 494

README

goflags

A wrapper on go flag library adding some convenience wrappers like better Usage, short and long flags, config file support, etc.

Thanks
  1. spf13/cobra - The very nice usage template for the command line.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToStringSlice added in v0.0.5

func ToStringSlice(value string) ([]string, error)

Types

type FlagData added in v0.0.5

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

func (*FlagData) Group added in v0.0.5

func (flagData *FlagData) Group(name string)

Group sets the group for a flag data

func (*FlagData) Hash added in v0.0.5

func (flagData *FlagData) Hash() string

Hash returns the unique hash for a flagData structure NOTE: Hash panics when the structure cannot be hashed.

type FlagSet

type FlagSet struct {
	Marshal bool

	// OtherOptionsGroupName is the name for all flags not in a group
	OtherOptionsGroupName string
	// contains filtered or unexported fields
}

FlagSet is a list of flags for an application

func NewFlagSet added in v0.0.5

func NewFlagSet() *FlagSet

NewFlagSet creates a new flagSet structure for the application

func (*FlagSet) BoolVar

func (flagSet *FlagSet) BoolVar(field *bool, long string, defaultValue bool, usage string) *FlagData

BoolVar adds a bool flag with a longname

func (*FlagSet) BoolVarP

func (flagSet *FlagSet) BoolVarP(field *bool, long, short string, defaultValue bool, usage string) *FlagData

BoolVarP adds a bool flag with a shortname and longname

func (*FlagSet) IntVar

func (flagSet *FlagSet) IntVar(field *int, long string, defaultValue int, usage string) *FlagData

IntVar adds a int flag with a longname

func (*FlagSet) IntVarP

func (flagSet *FlagSet) IntVarP(field *int, long, short string, defaultValue int, usage string) *FlagData

IntVarP adds a int flag with a shortname and longname

func (*FlagSet) MergeConfigFile

func (flagSet *FlagSet) MergeConfigFile(file string) error

MergeConfigFile reads a config file to merge values from.

func (*FlagSet) Parse

func (flagSet *FlagSet) Parse() error

Parse parses the flags provided to the library.

func (*FlagSet) SetDescription

func (flagSet *FlagSet) SetDescription(description string)

SetDescription sets the description field for a flagSet to a value.

func (*FlagSet) SetGroup added in v0.0.5

func (flagSet *FlagSet) SetGroup(name, description string)

SetGroup sets a group with name and description for the command line options

The order in which groups are passed is also kept as is, similar to flags.

func (*FlagSet) StringSliceVar

func (flagSet *FlagSet) StringSliceVar(field *StringSlice, long string, defaultValue []string, usage string) *FlagData

StringSliceVar adds a string slice flag with a longname

func (*FlagSet) StringSliceVarP

func (flagSet *FlagSet) StringSliceVarP(field *StringSlice, long, short string, defaultValue []string, usage string) *FlagData

StringSliceVarP adds a string slice flag with a shortname and longname

func (*FlagSet) StringVar

func (flagSet *FlagSet) StringVar(field *string, long, defaultValue, usage string) *FlagData

StringVar adds a string flag with a longname

func (*FlagSet) StringVarEnv added in v0.0.3

func (flagSet *FlagSet) StringVarEnv(field *string, long, short, defaultValue, envName, usage string) *FlagData

StringVarEnv adds a string flag with a shortname and longname with a default value read from env variable with a default value fallback

func (*FlagSet) StringVarP

func (flagSet *FlagSet) StringVarP(field *string, long, short, defaultValue, usage string) *FlagData

StringVarP adds a string flag with a shortname and longname

func (*FlagSet) Var added in v0.0.3

func (flagSet *FlagSet) Var(field flag.Value, long, usage string) *FlagData

Var adds a Var flag with a longname

func (*FlagSet) VarP added in v0.0.3

func (flagSet *FlagSet) VarP(field flag.Value, long, short, usage string) *FlagData

VarP adds a Var flag with a shortname and longname

type InsertionOrderedMap added in v0.0.5

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

func (*InsertionOrderedMap) Set added in v0.0.5

func (insertionOrderedMap *InsertionOrderedMap) Set(key string, value *FlagData)

type StringSlice

type StringSlice []string

StringSlice is a slice of strings

func (*StringSlice) Set

func (stringSlice *StringSlice) Set(value string) error

Set appends a value to the string slice.

func (*StringSlice) String

func (stringSlice *StringSlice) String() string

Jump to

Keyboard shortcuts

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