Documentation
¶
Overview ¶
Example (NewEntriesProvider_1) ¶
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"some-thing"}
_, err := NewEntriesProvider(params)
fmt.Println("when processing invalid params got error:")
fmt.Println(err)
Output: when processing invalid params got error: cmdline issue at position #1: arg "some-thing": invalid format
Example (NewEntriesProvider_2) ¶
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"--arg1=1", "--arg2=1", "--arg1=asdasd"}
_, err := NewEntriesProvider(params)
fmt.Println("when processing duplicated params got error:")
fmt.Println(err)
Output: when processing duplicated params got error: cmdline issue at position #3: --arg1 previous found at position #1: duplicate param
Example (NewEntriesProvider_3) ¶
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"--arg3=1", "--arg1=10", "--arg2=asdasd"}
provider, _ := NewEntriesProvider(params)
fmt.Println("when processing params got those entries:")
stringValues := provider.GetStringValues()
var keys []string
for key := range provider.GetStringValues() {
keys = append(keys, key)
}
sort.Strings(keys)
for i, key := range keys {
entry := stringValues[key]
fmt.Printf(
"%2d - location=%q key=%q value=%q\n",
i,
entry.Location,
key,
entry.Value,
)
}
Output: when processing params got those entries: 0 - location="cmdline[--arg1]" key="arg1" value="10" 1 - location="cmdline[--arg2]" key="arg2" value="asdasd" 2 - location="cmdline[--arg3]" key="arg3" value="1"
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateParam = errors.New("duplicate param")
ErrDuplicateParam represents an error when creating the provider with duplicated options in the command line.
var ErrInvalidFormat = errors.New("invalid format")
ErrInvalidFormat represents an error when creating the provider with an invalid command line option.
Functions ¶
This section is empty.
Types ¶
type EntriesProvider ¶
type EntriesProvider struct {
// contains filtered or unexported fields
}
EntriesProvider is an entries' provider that extract entries from command line.
func NewEntriesProvider ¶
func NewEntriesProvider(commandLine []string) (*EntriesProvider, error)
NewEntriesProvider creates an entries' provider that parses and extract parameters from command line.
Each command line parameter MUST match regexp '^--([a-z\d_-]+)=(.+)$'. ErrInvalidFormat is returned in such a case.
func (*EntriesProvider) GetStringValues ¶
func (ep *EntriesProvider) GetStringValues() svalue.Values
GetStringValues implements svalue.Provider interface.
type ParamError ¶
ParamError represents an error when creating the provider with invalid parameters.
func (*ParamError) Error ¶
func (e *ParamError) Error() string