commit
8111804d17
20
README.md
20
README.md
|
@ -37,7 +37,7 @@ arg.MustParse(&args)
|
|||
|
||||
```shell
|
||||
$ ./example
|
||||
usage: example --id ID [--timeout TIMEOUT]
|
||||
Usage: example --id ID [--timeout TIMEOUT]
|
||||
error: --id is required
|
||||
```
|
||||
|
||||
|
@ -108,13 +108,13 @@ arg.MustParse(&args)
|
|||
|
||||
```shell
|
||||
$ ./example -h
|
||||
usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]]
|
||||
Usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]]
|
||||
|
||||
positional arguments:
|
||||
input
|
||||
output
|
||||
Positional arguments:
|
||||
INPUT
|
||||
OUTPUT
|
||||
|
||||
options:
|
||||
Options:
|
||||
--verbose, -v verbosity level
|
||||
--dataset DATASET dataset to use
|
||||
--optimize OPTIMIZE, -O OPTIMIZE
|
||||
|
@ -178,7 +178,7 @@ if args.Foo == "" && args.Bar == "" {
|
|||
|
||||
```shell
|
||||
./example
|
||||
usage: samples [--foo FOO] [--bar BAR]
|
||||
Usage: samples [--foo FOO] [--bar BAR]
|
||||
error: you must provide one of --foo and --bar
|
||||
```
|
||||
|
||||
|
@ -275,7 +275,7 @@ $ ./example --name=foo.bar
|
|||
&main.NameDotName{Head:"foo", Tail:"bar"}
|
||||
|
||||
$ ./example --name=oops
|
||||
usage: example [--name NAME]
|
||||
Usage: example [--name NAME]
|
||||
error: error processing --name: missing period in "oops"
|
||||
```
|
||||
|
||||
|
@ -299,9 +299,9 @@ func main() {
|
|||
```shell
|
||||
$ ./example -h
|
||||
this program does this and that
|
||||
usage: example [--foo FOO]
|
||||
Usage: example [--foo FOO]
|
||||
|
||||
options:
|
||||
Options:
|
||||
--foo FOO
|
||||
--help, -h display this help and exit
|
||||
```
|
||||
|
|
8
usage.go
8
usage.go
|
@ -33,7 +33,7 @@ func (p *Parser) WriteUsage(w io.Writer) {
|
|||
fmt.Fprintln(w, p.version)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "usage: %s", p.config.Program)
|
||||
fmt.Fprintf(w, "Usage: %s", p.config.Program)
|
||||
|
||||
// write the option component of the usage message
|
||||
for _, spec := range options {
|
||||
|
@ -80,9 +80,9 @@ func (p *Parser) WriteHelp(w io.Writer) {
|
|||
|
||||
// write the list of positionals
|
||||
if len(positionals) > 0 {
|
||||
fmt.Fprint(w, "\npositional arguments:\n")
|
||||
fmt.Fprint(w, "\nPositional arguments:\n")
|
||||
for _, spec := range positionals {
|
||||
left := " " + spec.long
|
||||
left := " " + strings.ToUpper(spec.long)
|
||||
fmt.Fprint(w, left)
|
||||
if spec.help != "" {
|
||||
if len(left)+2 < colWidth {
|
||||
|
@ -97,7 +97,7 @@ func (p *Parser) WriteHelp(w io.Writer) {
|
|||
}
|
||||
|
||||
// write the list of options
|
||||
fmt.Fprint(w, "\noptions:\n")
|
||||
fmt.Fprint(w, "\nOptions:\n")
|
||||
for _, spec := range options {
|
||||
printOption(w, spec)
|
||||
}
|
||||
|
|
|
@ -10,15 +10,15 @@ import (
|
|||
)
|
||||
|
||||
func TestWriteUsage(t *testing.T) {
|
||||
expectedUsage := "usage: example [--name NAME] [--value VALUE] [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--ids IDS] [--values VALUES] [--workers WORKERS] INPUT [OUTPUT [OUTPUT ...]]\n"
|
||||
expectedUsage := "Usage: example [--name NAME] [--value VALUE] [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--ids IDS] [--values VALUES] [--workers WORKERS] INPUT [OUTPUT [OUTPUT ...]]\n"
|
||||
|
||||
expectedHelp := `usage: example [--name NAME] [--value VALUE] [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--ids IDS] [--values VALUES] [--workers WORKERS] INPUT [OUTPUT [OUTPUT ...]]
|
||||
expectedHelp := `Usage: example [--name NAME] [--value VALUE] [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--ids IDS] [--values VALUES] [--workers WORKERS] INPUT [OUTPUT [OUTPUT ...]]
|
||||
|
||||
positional arguments:
|
||||
input
|
||||
output list of outputs
|
||||
Positional arguments:
|
||||
INPUT
|
||||
OUTPUT list of outputs
|
||||
|
||||
options:
|
||||
Options:
|
||||
--name NAME name to use [default: Foo Bar]
|
||||
--value VALUE secret value [default: 42]
|
||||
--verbose, -v verbosity level
|
||||
|
@ -61,13 +61,13 @@ options:
|
|||
}
|
||||
|
||||
func TestUsageLongPositionalWithHelp(t *testing.T) {
|
||||
expectedHelp := `usage: example VERYLONGPOSITIONALWITHHELP
|
||||
expectedHelp := `Usage: example VERYLONGPOSITIONALWITHHELP
|
||||
|
||||
positional arguments:
|
||||
verylongpositionalwithhelp
|
||||
Positional arguments:
|
||||
VERYLONGPOSITIONALWITHHELP
|
||||
this positional argument is very long
|
||||
|
||||
options:
|
||||
Options:
|
||||
--help, -h display this help and exit
|
||||
`
|
||||
var args struct {
|
||||
|
@ -84,9 +84,9 @@ options:
|
|||
}
|
||||
|
||||
func TestUsageWithProgramName(t *testing.T) {
|
||||
expectedHelp := `usage: myprogram
|
||||
expectedHelp := `Usage: myprogram
|
||||
|
||||
options:
|
||||
Options:
|
||||
--help, -h display this help and exit
|
||||
`
|
||||
config := Config{
|
||||
|
@ -110,9 +110,9 @@ func (versioned) Version() string {
|
|||
|
||||
func TestUsageWithVersion(t *testing.T) {
|
||||
expectedHelp := `example 3.2.1
|
||||
usage: example
|
||||
Usage: example
|
||||
|
||||
options:
|
||||
Options:
|
||||
--help, -h display this help and exit
|
||||
--version display version and exit
|
||||
`
|
||||
|
@ -139,9 +139,9 @@ func (described) Description() string {
|
|||
|
||||
func TestUsageWithDescription(t *testing.T) {
|
||||
expectedHelp := `this program does this and that
|
||||
usage: example
|
||||
Usage: example
|
||||
|
||||
options:
|
||||
Options:
|
||||
--help, -h display this help and exit
|
||||
`
|
||||
os.Args[0] = "example"
|
||||
|
|
Loading…
Reference in New Issue