Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFlagAlreadyAdded appears when trying to register a flag with // an already used name (field Name). ErrFlagAlreadyAdded = errors.New("flag already added") // ErrNoSuchFlag appears when trying to request a value for a flag // that wasn't registered. ErrNoSuchFlag = errors.New("no such flag") )
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag struct { // This value will be reflected. DefaultValue interface{} // Flag name. It will be accessible using this name later. Name string // Description for help output. Description string // Type can be one of "bool", "int", "string". Type string }
Flag represents addable flag for Flagger.
type Flagger ¶
type Flagger struct {
// contains filtered or unexported fields
}
Flagger implements (kinda) extended CLI parameters parser. As it available from CommonContext, these flags will be available to whole application.
It uses reflection to determine what kind of variable we should parse or get.
func New ¶
func New(appName string, l LoggerInterface) *Flagger
New creates new Flagger instance. If no logger will be passed - we will use default "log" module and will print logs to stdout.
func (*Flagger) GetBoolValue ¶
GetBoolValue returns boolean value for flag with given name. Returns bool value for flag and nil as error on success and false bool plus error with text on error.
func (*Flagger) GetIntValue ¶
GetIntValue returns integer value for flag with given name. Returns integer on success and 0 on error.
func (*Flagger) GetStringValue ¶
GetStringValue returns string value for flag with given name. Returns string on success or empty string on error.
type LoggerInterface ¶
type LoggerInterface interface { Fatal(v ...interface{}) Print(v ...interface{}) }
LoggerInterface provide logging interface, so everyone can inject own logging handlers.