new /v2 subdirectory
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type argSpec interface {
|
||||
getBase() *argBase
|
||||
parse(cli *CliParser, specIndex int, args []string, argIndex int) (consumedArgs int, err error)
|
||||
}
|
||||
|
||||
type argBase struct {
|
||||
name string
|
||||
description string
|
||||
required bool
|
||||
repeat bool
|
||||
}
|
||||
|
||||
// -------------- Argument Template functions ----------------
|
||||
func (cli *CliParser) getArgTemplate(spec argSpec) (templ string) {
|
||||
arg := spec.getBase()
|
||||
templ = "<" + arg.name + ">"
|
||||
if arg.repeat {
|
||||
templ += " ..."
|
||||
}
|
||||
if !arg.required {
|
||||
templ = "[" + templ + "]"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *CliParser) getArgsTemplate() (argsTemplate string) {
|
||||
templates := make([]string, len(cli.argSpecs))
|
||||
for i, argSpec := range cli.argSpecs {
|
||||
templates[i] = cli.getArgTemplate(argSpec)
|
||||
}
|
||||
|
||||
argsTemplate = strings.Join(templates, " ")
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user