new /v2 subdirectory
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package cli
|
||||
|
||||
// -------------- argString ----------------
|
||||
type argString struct {
|
||||
base argBase
|
||||
targetVar *string
|
||||
}
|
||||
|
||||
func (arg *argString) getBase() *argBase {
|
||||
return &arg.base
|
||||
}
|
||||
|
||||
func (spec *argString) parse(cli *CliParser, specIndex int, args []string, argIndex int) (consumedArgs int, err error) {
|
||||
consumedArgs = 1
|
||||
if spec.targetVar != nil {
|
||||
if argIndex < len(args) {
|
||||
*spec.targetVar = args[argIndex]
|
||||
} else if spec.base.required {
|
||||
err = errMissingRequiredArg(spec.base.name)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *CliParser) AddStringArg(name string, required bool, targetVar *string, description string) {
|
||||
// todo: check if arg already exists
|
||||
cli.argSpecs = append(cli.argSpecs, &argString{
|
||||
base: argBase{
|
||||
name: name,
|
||||
description: description,
|
||||
required: required,
|
||||
repeat: false,
|
||||
},
|
||||
targetVar: targetVar,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user