added program name and description to the help output
This commit is contained in:
parent
9e2e5c1f37
commit
69f550884a
@ -11,6 +11,12 @@ func (cli *CliParser) Usage() string {
|
|||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
|
||||||
program, _ := cli.GetVersionSection("program")
|
program, _ := cli.GetVersionSection("program")
|
||||||
|
fmt.Fprint(&sb, "NAME", program)
|
||||||
|
if cli.description != "" {
|
||||||
|
fmt.Fprint(&sb, "-", cli.description)
|
||||||
|
}
|
||||||
|
sb.WriteByte('\n')
|
||||||
|
|
||||||
publicCount := cli.publicOptionCount()
|
publicCount := cli.publicOptionCount()
|
||||||
if publicCount > 0 {
|
if publicCount > 0 {
|
||||||
fmt.Fprintf(&sb, "USAGE: %s [<options>] %s\n", program, cli.getArgsTemplate())
|
fmt.Fprintf(&sb, "USAGE: %s [<options>] %s\n", program, cli.getArgsTemplate())
|
||||||
|
|||||||
19
cli.go
19
cli.go
@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CliOptionTracer interface {
|
type CliOptionTracer interface {
|
||||||
@ -38,17 +39,33 @@ type OptReference interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CliParser struct {
|
type CliParser struct {
|
||||||
|
description string
|
||||||
version string
|
version string
|
||||||
options []cliOptionParser
|
options []cliOptionParser
|
||||||
argSpecs []argSpec
|
argSpecs []argSpec
|
||||||
cliArgs []string
|
cliArgs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *CliParser) Init(argv []string, version string) {
|
func (cli *CliParser) Init(argv []string, version string, description string) {
|
||||||
cli.version = version
|
cli.version = version
|
||||||
|
cli.description = description
|
||||||
cli.cliArgs = argv
|
cli.cliArgs = argv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cli *CliParser) GetOption(name string) (ref OptReference) {
|
||||||
|
var opt cliOptionParser
|
||||||
|
if strings.HasPrefix(name, "-") {
|
||||||
|
opt = cli.findOptionByArg(name)
|
||||||
|
} else {
|
||||||
|
opt = cli.findOptionByName(name)
|
||||||
|
}
|
||||||
|
if opt != nil {
|
||||||
|
ref = opt.(OptReference)
|
||||||
|
}
|
||||||
|
return ref
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func (cli *CliParser) SetIncompatibleOption(optName string, incompatibleOptNames ...string) error {
|
func (cli *CliParser) SetIncompatibleOption(optName string, incompatibleOptNames ...string) error {
|
||||||
var opti cliOptionParser
|
var opti cliOptionParser
|
||||||
if opti = cli.findOptionByName(optName); opti == nil {
|
if opti = cli.findOptionByName(optName); opti == nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user