summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-28 20:26:26 -0500
committerJeff Carr <[email protected]>2025-10-28 20:26:26 -0500
commitdd3a0b96d3df37a17912fb8921d76d6eb100557a (patch)
tree290adf32dcdc6b66278f6c5b442d60df9325d42c
parent27fc781490a9594e347a57378ded765febac82f4 (diff)
more parsing work
-rw-r--r--parse.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/parse.go b/parse.go
index cc2161e..bdeec1d 100644
--- a/parse.go
+++ b/parse.go
@@ -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