Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ type Options struct {
positional bool
}

// Default argument options to use when user does not specify them.
var DefaultArgOptions = Options{}

// NewParser creates new Parser object that will allow to add arguments for parsing
// It takes program name and description which will be used as part of Usage output
// Returns pointer to Parser object
Expand Down
6 changes: 6 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func (o *Command) addArg(a *arg) error {
}
a.parent = o

// Ensure Options pointer is not nil; use default options if none provided
if a.opts == nil {
opts := DefaultArgOptions
a.opts = &opts
}

if a.GetPositional() {
switch a.argType { // Secondary guard
case Flag, FlagCounter, StringList, IntList, FloatList, FileList:
Expand Down