|
|
|
@ -8,170 +8,143 @@ import ( |
|
|
|
|
"time" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// configParameterOptions represents additional options for a configParameter.
|
|
|
|
|
type configParameterOptions struct { |
|
|
|
|
sw, hidden, command bool |
|
|
|
|
callback func() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// configParameter represents a single configuration parameter.
|
|
|
|
|
type configParameter struct { |
|
|
|
|
name string // duplicated in configMap, but also saved here for convenience
|
|
|
|
|
value, def any // value and default value
|
|
|
|
|
description string // description for this parameter
|
|
|
|
|
parsed bool // true if it was successfully parsed from commandline
|
|
|
|
|
configParameterOptions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type configParameterTypeUnion = interface { |
|
|
|
|
bool | int | uint | float64 | string | []int | []uint | []float64 | []string | []bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var configMap = map[string]configParameter{} |
|
|
|
|
var configAliasMap = map[string]string{} |
|
|
|
|
|
|
|
|
|
var configParsingFinished = false |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
// registration
|
|
|
|
|
|
|
|
|
|
func registerConfigParameter[T configParameterTypeUnion](name string, def T, description string, opts configParameterOptions) { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
|
|
|
|
|
_, ok := configMap[name] |
|
|
|
|
failIf(ok, "cannot register config parameter (already exists): \"%v\"", name) |
|
|
|
|
func init() { |
|
|
|
|
registerCommand("help", "show program usage", func() { |
|
|
|
|
log("", 0, "options:") |
|
|
|
|
|
|
|
|
|
_, ok = configAliasMap[name] |
|
|
|
|
failIf(ok, "cannot register config parameter (already exists as an alias): \"%v\"", name) |
|
|
|
|
parms := make([]string, 0, len(configMap)) |
|
|
|
|
for key := range configMap { |
|
|
|
|
parms = append(parms, key) |
|
|
|
|
} |
|
|
|
|
sort.Strings(parms) |
|
|
|
|
|
|
|
|
|
failIf(opts.command && opts.callback == nil, "\"%v\" is defined as a command but callback is missing", name) |
|
|
|
|
for _, parmName := range parms { |
|
|
|
|
parm := configMap[parmName] |
|
|
|
|
|
|
|
|
|
configMap[name] = configParameter{name: name, value: def, def: def, description: description, |
|
|
|
|
configParameterOptions: opts} |
|
|
|
|
if parm.hidden { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerParam[T configParameterTypeUnion](name string, def T, description string) { |
|
|
|
|
registerConfigParameter(name, def, description, configParameterOptions{}) |
|
|
|
|
header := "-" + parm.name |
|
|
|
|
if len(parm.name) > 1 { |
|
|
|
|
header = "-" + header |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerParamEx[T configParameterTypeUnion](name string, def T, description string, options configParameterOptions) { |
|
|
|
|
registerConfigParameter(name, def, description, options) |
|
|
|
|
aliases := []string{} |
|
|
|
|
for alias, target := range configAliasMap { |
|
|
|
|
if target == parm.name { |
|
|
|
|
if len(alias) == 1 { |
|
|
|
|
aliases = append(aliases, "-"+alias) |
|
|
|
|
} else { |
|
|
|
|
aliases = append(aliases, "--"+alias) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerParamHidden[T configParameterTypeUnion](name string, def T) { |
|
|
|
|
registerConfigParameter(name, def, "", configParameterOptions{hidden: true}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerParamWithCallback[T configParameterTypeUnion](name string, def T, description string, callback func()) { |
|
|
|
|
registerConfigParameter(name, def, description, configParameterOptions{callback: callback}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerCommand(name string, description string, callback func()) { |
|
|
|
|
registerConfigParameter(name, false, description, configParameterOptions{command: true, callback: callback}) |
|
|
|
|
if len(aliases) > 0 { |
|
|
|
|
sort.Strings(aliases) |
|
|
|
|
header = header + " (aliases: " + strings.Join(aliases, ", ") + ")" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerSwitch(name string, description string) { |
|
|
|
|
registerConfigParameter(name, false, description, configParameterOptions{sw: true}) |
|
|
|
|
header = header + ":" |
|
|
|
|
description := " (description missing)" |
|
|
|
|
if parm.description != "" { |
|
|
|
|
description = " " + parm.description |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerAlias(alias, target string) { |
|
|
|
|
alias, target = strings.ToLower(alias), strings.ToLower(target) |
|
|
|
|
|
|
|
|
|
_, ok := configAliasMap[alias] |
|
|
|
|
failIf(ok, "cannot register alias (already exists): \"%v\"", alias) |
|
|
|
|
|
|
|
|
|
_, ok = configMap[alias] |
|
|
|
|
failIf(ok, "cannot register alias (already exists as a config parameter): \"%v\"", alias) |
|
|
|
|
|
|
|
|
|
_, ok = configMap[target] |
|
|
|
|
failIf(!ok, "cannot register alias \"%v\": target \"%v\" does not exist", alias, target) |
|
|
|
|
|
|
|
|
|
configAliasMap[alias] = target |
|
|
|
|
if parm.command || parm.sw { |
|
|
|
|
log("", 0, "%s\n%s", header, description) |
|
|
|
|
} else { |
|
|
|
|
log("", 0, "%s\n%s\n default: %v", header, description, parm.value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
// acquisition
|
|
|
|
|
|
|
|
|
|
func getParamGeneric(name string) any { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
log("", 0, "") |
|
|
|
|
log("", 0, "examples:") |
|
|
|
|
log("", 0, " single target:") |
|
|
|
|
log("", 0, " ./mtbf --ip 127.0.0.1 --port 8291 --login admin --password 12345678 --out-file good.txt") |
|
|
|
|
log("", 0, " multiple targets with multiple passwords:") |
|
|
|
|
log("", 0, " ./mtbf --ip-list ips.txt --port 8291 --login admin --password-list passwords.txt --out-file good.txt") |
|
|
|
|
|
|
|
|
|
parm, ok := configMap[name] |
|
|
|
|
failIf(!ok, "unknown config parameter: \"%v\"", name) |
|
|
|
|
failIf(parm.command, "config parameter \"%v\" is a command", name) |
|
|
|
|
os.Exit(0) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if parm.sw { |
|
|
|
|
return parm.parsed // switches always return true if they were parsed
|
|
|
|
|
} else if parm.parsed || parm.hidden { |
|
|
|
|
return parm.value // parsed and hidden parms return their current value
|
|
|
|
|
} else { |
|
|
|
|
return parm.def // otherwise, use default value
|
|
|
|
|
} |
|
|
|
|
registerAlias("?", "help") |
|
|
|
|
registerAlias("h", "help") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParam[T configParameterTypeUnion](name string) T { |
|
|
|
|
return getParamGeneric(name).(T) |
|
|
|
|
// configParameterOptions represents additional options for a configParameter.
|
|
|
|
|
type configParameterOptions struct { |
|
|
|
|
sw, hidden, command bool |
|
|
|
|
callback func() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParamInt(name string) int { |
|
|
|
|
return getParam[int](name) |
|
|
|
|
// configParameter represents a single configuration parameter.
|
|
|
|
|
type configParameter struct { |
|
|
|
|
name string // duplicated in configMap, but also saved here for convenience
|
|
|
|
|
value, def any // value and default value
|
|
|
|
|
description string // description for this parameter
|
|
|
|
|
parsed bool // true if it was successfully parsed from commandline
|
|
|
|
|
configParameterOptions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParamFloat(name string) float64 { |
|
|
|
|
return getParam[float64](name) |
|
|
|
|
type configParameterTypeUnion = interface { |
|
|
|
|
bool | int | uint | float64 | string | []int | []uint | []float64 | []string | []bool | map[string]bool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParamIntSlice(name string) []int { |
|
|
|
|
return getParam[[]int](name) |
|
|
|
|
} |
|
|
|
|
// --------------
|
|
|
|
|
// parsing
|
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
|
|
func getParamBool(name string) bool { |
|
|
|
|
return getParam[bool](name) |
|
|
|
|
} |
|
|
|
|
func parseAppConfig() { |
|
|
|
|
log("cfg", 1, "parsing config") |
|
|
|
|
|
|
|
|
|
func getParamSwitch(name string) bool { |
|
|
|
|
return getParamBool(name) |
|
|
|
|
} |
|
|
|
|
totalFinalized := 0 |
|
|
|
|
|
|
|
|
|
func getParamString(name string) string { |
|
|
|
|
return getParam[string](name) |
|
|
|
|
for i := 1; i < len(os.Args); i++ { |
|
|
|
|
arg := getCmdlineParm(i) |
|
|
|
|
if len(arg) == 0 { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParamStringSlice(name string) []string { |
|
|
|
|
return getParam[[]string](name) |
|
|
|
|
} |
|
|
|
|
failIf(arg[0] != '-', "\"%v\" is not a commandline parameter", arg) |
|
|
|
|
arg = strings.TrimPrefix(arg, "-") |
|
|
|
|
arg = strings.TrimPrefix(arg, "-") |
|
|
|
|
|
|
|
|
|
func getParamDurationMS(name string) time.Duration { |
|
|
|
|
tm := getParam[int](name) |
|
|
|
|
failIf(tm < -1, "\"%v\" can only be set to -1 or a positive value", name) |
|
|
|
|
if tm == -1 { |
|
|
|
|
tm = 0 |
|
|
|
|
} |
|
|
|
|
failIf(len(arg) == 0, "\"%v\" is not a commandline parameter", getCmdlineParm(i)) |
|
|
|
|
|
|
|
|
|
return time.Duration(tm) * time.Millisecond |
|
|
|
|
} |
|
|
|
|
parm, ok := configMap[strings.ToLower(arg)] |
|
|
|
|
if !ok { |
|
|
|
|
alias, ok := configAliasMap[strings.ToLower(arg)] |
|
|
|
|
failIf(!ok, "unknown commandline parameter: \"%v\"", arg) |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
// setting
|
|
|
|
|
parm, ok = configMap[alias] |
|
|
|
|
failIf(!ok, "alias \"%v\" references unknown commandline parameter", arg) |
|
|
|
|
|
|
|
|
|
func setParam(name string, value any) { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
log("cfg", 3, "\"%v\" is aliased to \"%v\"", alias, parm.name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
parm, ok := configMap[name] |
|
|
|
|
failIf(!ok, "unknown config parameter: \"%v\"", name) |
|
|
|
|
failIf(parm.hidden, "config parameter \"%v\" is hidden and cannot be set", name) |
|
|
|
|
failIf(parm.command, "config parameter \"%v\" is a command and cannot be set", name) |
|
|
|
|
failIf(parm.sw && !value.(bool), "config parameter \"%v\" is a switch and only accepts boolean arguments", name) |
|
|
|
|
failIf(parm.hidden, "\"%v\" is not a commandline parameter", getCmdlineParm(i)) |
|
|
|
|
failIf(parm.parsed && !parm.isSlice(), "multiple occurrences of commandline parameter \"%v\" are not allowed", parm.name) |
|
|
|
|
|
|
|
|
|
parm.value = value |
|
|
|
|
if parm.callback != nil { |
|
|
|
|
parm.callback() |
|
|
|
|
if !parm.command { |
|
|
|
|
if parm.sw { |
|
|
|
|
parm.writeParmValue("true") |
|
|
|
|
} else { |
|
|
|
|
i++ |
|
|
|
|
parm.writeParmValue(getCmdlineParm(i)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
configMap[name] = parm |
|
|
|
|
parm.finalize() |
|
|
|
|
totalFinalized++ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
// parsing
|
|
|
|
|
log("cfg", 1, "parsed %v commandline parameters", totalFinalized) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// getCmdlineParm retrieves a commandline parameter with index i.
|
|
|
|
|
func getCmdlineParm(i int) string { |
|
|
|
@ -238,117 +211,139 @@ func (parm *configParameter) finalize() { |
|
|
|
|
log("cfg", 2, "parse: %T \"%v\" -> def %v, now %v", parm.value, parm.name, parm.def, parm.value) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func parseAppConfig() { |
|
|
|
|
log("cfg", 1, "parsing config") |
|
|
|
|
|
|
|
|
|
totalFinalized := 0 |
|
|
|
|
// --------------
|
|
|
|
|
// registration
|
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
|
|
for i := 1; i < len(os.Args); i++ { |
|
|
|
|
arg := getCmdlineParm(i) |
|
|
|
|
if len(arg) == 0 { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
func registerConfigParameter[T configParameterTypeUnion](name string, def T, description string, opts configParameterOptions) { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
|
|
|
|
|
failIf(arg[0] != '-', "\"%v\" is not a commandline parameter", arg) |
|
|
|
|
arg = strings.TrimPrefix(arg, "-") |
|
|
|
|
arg = strings.TrimPrefix(arg, "-") |
|
|
|
|
_, ok := configMap[name] |
|
|
|
|
failIf(ok, "cannot register config parameter (already exists): \"%v\"", name) |
|
|
|
|
|
|
|
|
|
failIf(len(arg) == 0, "\"%v\" is not a commandline parameter", getCmdlineParm(i)) |
|
|
|
|
_, ok = configAliasMap[name] |
|
|
|
|
failIf(ok, "cannot register config parameter (already exists as an alias): \"%v\"", name) |
|
|
|
|
|
|
|
|
|
parm, ok := configMap[strings.ToLower(arg)] |
|
|
|
|
if !ok { |
|
|
|
|
alias, ok := configAliasMap[strings.ToLower(arg)] |
|
|
|
|
failIf(!ok, "unknown commandline parameter: \"%v\"", arg) |
|
|
|
|
failIf(opts.command && opts.callback == nil, "\"%v\" is defined as a command but callback is missing", name) |
|
|
|
|
|
|
|
|
|
parm, ok = configMap[alias] |
|
|
|
|
failIf(!ok, "alias \"%v\" references unknown commandline parameter", arg) |
|
|
|
|
configMap[name] = configParameter{name: name, value: def, def: def, description: description, |
|
|
|
|
configParameterOptions: opts} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log("cfg", 3, "\"%v\" is aliased to \"%v\"", alias, parm.name) |
|
|
|
|
func registerParam[T configParameterTypeUnion](name string, def T, description string) { |
|
|
|
|
registerConfigParameter(name, def, description, configParameterOptions{}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
failIf(parm.hidden, "\"%v\" is not a commandline parameter", getCmdlineParm(i)) |
|
|
|
|
failIf(parm.parsed && !parm.isSlice(), "multiple occurrences of commandline parameter \"%v\" are not allowed", parm.name) |
|
|
|
|
func registerParamHidden[T configParameterTypeUnion](name string, def T) { |
|
|
|
|
registerConfigParameter(name, def, "", configParameterOptions{hidden: true}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !parm.command { |
|
|
|
|
if parm.sw { |
|
|
|
|
parm.writeParmValue("true") |
|
|
|
|
} else { |
|
|
|
|
i++ |
|
|
|
|
parm.writeParmValue(getCmdlineParm(i)) |
|
|
|
|
func registerParamWithCallback[T configParameterTypeUnion](name string, def T, description string, callback func()) { |
|
|
|
|
registerConfigParameter(name, def, description, configParameterOptions{callback: callback}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func registerCommand(name string, description string, callback func()) { |
|
|
|
|
registerConfigParameter(name, false, description, configParameterOptions{command: true, callback: callback}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
parm.finalize() |
|
|
|
|
totalFinalized++ |
|
|
|
|
func registerSwitch(name string, description string) { |
|
|
|
|
registerConfigParameter(name, false, description, configParameterOptions{sw: true}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log("cfg", 1, "parsed %v commandline parameters", totalFinalized) |
|
|
|
|
configParsingFinished = true |
|
|
|
|
func registerAlias(alias, target string) { |
|
|
|
|
alias, target = strings.ToLower(alias), strings.ToLower(target) |
|
|
|
|
|
|
|
|
|
_, ok := configAliasMap[alias] |
|
|
|
|
failIf(ok, "cannot register alias (already exists): \"%v\"", alias) |
|
|
|
|
|
|
|
|
|
_, ok = configMap[alias] |
|
|
|
|
failIf(ok, "cannot register alias (already exists as a config parameter): \"%v\"", alias) |
|
|
|
|
|
|
|
|
|
_, ok = configMap[target] |
|
|
|
|
failIf(!ok, "cannot register alias \"%v\": target \"%v\" does not exist", alias, target) |
|
|
|
|
|
|
|
|
|
configAliasMap[alias] = target |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func showHelp() { |
|
|
|
|
log("", 0, "options:") |
|
|
|
|
// --------------
|
|
|
|
|
// acquisition
|
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
|
|
parms := make([]string, 0, len(configMap)) |
|
|
|
|
for key := range configMap { |
|
|
|
|
parms = append(parms, key) |
|
|
|
|
func getParamGeneric(name string) any { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
|
|
|
|
|
parm, ok := configMap[name] |
|
|
|
|
failIf(!ok, "unknown config parameter: \"%v\"", name) |
|
|
|
|
failIf(parm.command, "config parameter \"%v\" is a command", name) |
|
|
|
|
|
|
|
|
|
if parm.sw { |
|
|
|
|
return parm.parsed // switches always return true if they were parsed
|
|
|
|
|
} else if parm.parsed || parm.hidden { |
|
|
|
|
return parm.value // parsed and hidden parms return their current value
|
|
|
|
|
} else { |
|
|
|
|
return parm.def // otherwise, use default value
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sort.Strings(parms) |
|
|
|
|
|
|
|
|
|
for _, parmName := range parms { |
|
|
|
|
parm := configMap[parmName] |
|
|
|
|
func getParam[T configParameterTypeUnion](name string) T { |
|
|
|
|
return getParamGeneric(name).(T) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if parm.hidden { |
|
|
|
|
continue |
|
|
|
|
func getParamInt(name string) int { |
|
|
|
|
return getParam[int](name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
header := "-" + parm.name |
|
|
|
|
if len(parm.name) > 1 { |
|
|
|
|
header = "-" + header |
|
|
|
|
func getParamFloat(name string) float64 { |
|
|
|
|
return getParam[float64](name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
aliases := []string{} |
|
|
|
|
for alias, target := range configAliasMap { |
|
|
|
|
if target == parm.name { |
|
|
|
|
if len(alias) == 1 { |
|
|
|
|
aliases = append(aliases, "-"+alias) |
|
|
|
|
} else { |
|
|
|
|
aliases = append(aliases, "--"+alias) |
|
|
|
|
func getParamIntSlice(name string) []int { |
|
|
|
|
return getParam[[]int](name) |
|
|
|
|
} |
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
func getParamBool(name string) bool { |
|
|
|
|
return getParam[bool](name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getParamSwitch(name string) bool { |
|
|
|
|
return getParamBool(name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(aliases) > 0 { |
|
|
|
|
sort.Strings(aliases) |
|
|
|
|
header = header + " (aliases: " + strings.Join(aliases, ", ") + ")" |
|
|
|
|
func getParamString(name string) string { |
|
|
|
|
return getParam[string](name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
header = header + ":" |
|
|
|
|
description := " (description missing)" |
|
|
|
|
if parm.description != "" { |
|
|
|
|
description = " " + parm.description |
|
|
|
|
func getParamStringSlice(name string) []string { |
|
|
|
|
return getParam[[]string](name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if parm.command || parm.sw { |
|
|
|
|
log("", 0, "%s\n%s", header, description) |
|
|
|
|
} else { |
|
|
|
|
log("", 0, "%s\n%s\n default: %v", header, description, parm.value) |
|
|
|
|
func getParamDurationMS(name string) time.Duration { |
|
|
|
|
tm := getParam[int](name) |
|
|
|
|
failIf(tm < -1, "\"%v\" can only be set to -1 or a positive value", name) |
|
|
|
|
if tm == -1 { |
|
|
|
|
tm = 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return time.Duration(tm) * time.Millisecond |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log("", 0, "") |
|
|
|
|
log("", 0, "examples:") |
|
|
|
|
log("", 0, " single target:") |
|
|
|
|
log("", 0, " ./mtbf --ip 127.0.0.1 --port 8291 --login admin --password 12345678 --out-file good.txt") |
|
|
|
|
log("", 0, " multiple targets with multiple passwords:") |
|
|
|
|
log("", 0, " ./mtbf --ip-list ips.txt --port 8291 --login admin --password-list passwords.txt --out-file good.txt") |
|
|
|
|
// --------------
|
|
|
|
|
// setting
|
|
|
|
|
// --------------
|
|
|
|
|
|
|
|
|
|
os.Exit(0) |
|
|
|
|
func setParam(name string, value any) { |
|
|
|
|
name = strings.ToLower(name) |
|
|
|
|
|
|
|
|
|
parm, ok := configMap[name] |
|
|
|
|
failIf(!ok, "unknown config parameter: \"%v\"", name) |
|
|
|
|
failIf(parm.hidden, "config parameter \"%v\" is hidden and cannot be set", name) |
|
|
|
|
failIf(parm.command, "config parameter \"%v\" is a command and cannot be set", name) |
|
|
|
|
failIf(parm.sw && !value.(bool), "config parameter \"%v\" is a switch and only accepts boolean arguments", name) |
|
|
|
|
|
|
|
|
|
parm.value = value |
|
|
|
|
if parm.callback != nil { |
|
|
|
|
parm.callback() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
registerCommand("help", "show program usage", showHelp) |
|
|
|
|
registerAlias("?", "help") |
|
|
|
|
registerAlias("h", "help") |
|
|
|
|
configMap[name] = parm |
|
|
|
|
} |
|
|
|
|