diff --git a/argparse.go b/argparse.go index cb2cf28..c8c02ad 100644 --- a/argparse.go +++ b/argparse.go @@ -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 diff --git a/command.go b/command.go index f87d411..27637b6 100644 --- a/command.go +++ b/command.go @@ -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: