Closed hhromic closed 2 months ago
I just noticed that default values are also not reported in the help text either.
For example:
package main
import (
"fmt"
"github.com/alexflint/go-arg"
)
type args struct {
Number int `arg:"positional,env:NUMBER" default:"1" placeholder:"NUMBER" help:"a number to process"`
Verbose bool `arg:"--verbose,env:VERBOSE" default:"false" help:"show more about the processing"`
}
func main() {
var args args
arg.MustParse(&args)
fmt.Printf("%+v\n", args)
}
$ go run main.go
{Number:1 Verbose:false}
$ NUMBER=5 go run main.go
{Number:5 Verbose:false}
$ go run main.go -h
Usage: main [--verbose] [NUMBER]
Positional arguments:
NUMBER a number to process
Options:
--verbose show more about the processing [default: false, env: VERBOSE]
--help, -h display this help and exit
If a positional argument is configured with an environment variable, the name is not shown in the help text like other arguments.
Consider the following MRE:
And consider the following interactions with the program:
As it can be seen, when the positional argument is missing, go-arg correctly mentions that it can be provided using the
NUMBERS
environment variable. However this is not mentioned in the help text, like the--verbose
argument.I will prepare a PR to amend this soon.