diff options
| -rw-r--r-- | parse.go | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -12,6 +12,7 @@ import ( "strings" scalar "github.com/alexflint/go-scalar" + "go.wit.com/lib/protobuf/argvpb" ) // path represents a sequence of steps to find the output location for an @@ -97,6 +98,15 @@ func Register(dest ...interface{}) { } // MustParse processes command line arguments and exits upon failure +func MustParseArgv(dest ...interface{}) *Parser { + register = append(register, dest...) + if len(overrideFlags) == 0 { + overrideFlags = append(overrideFlags, argvpb.Real()...) + } + return mustParse(Config{Exit: mustParseExit, Out: mustParseOut}, register...) +} + +// MustParse processes command line arguments and exits upon failure func MustParse(dest ...interface{}) *Parser { register = append(register, dest...) return mustParse(Config{Exit: mustParseExit, Out: mustParseOut}, register...) @@ -127,6 +137,7 @@ func Parse(dest ...interface{}) error { // flags gets all command line arguments other than the first (program name) func flags() []string { if len(overrideFlags) > 0 { + // fmt.Fprintf(os.Stderr, "got to overrideFlags() (%v)\n", overrideFlags) return overrideFlags } if len(os.Args) == 0 { // os.Args could be empty @@ -795,7 +806,7 @@ func (p *Parser) process(args []string) error { } } if len(positionals) > 0 { - return fmt.Errorf("too many positional arguments at '%s'", positionals[0]) + return fmt.Errorf("too many positional arguments at '%s' (%v)", positionals[0], args) } // fill in defaults and check that all the required args were provided |
