From 0f6d10758d798e686522497e36fd1d979313aea2 Mon Sep 17 00:00:00 2001 From: Densest Void Date: Thu, 17 Oct 2019 21:57:18 -0400 Subject: [PATCH 1/4] Finishes addressing issue #29 Adds a Settings struct for creating parsers/commands with NewParserWithSettings or NewCommandWithSettings. Settings HelpDisabled - defaults false, set true to not generate a help argument for parser/command HelpSname - short name for the parser/command help argument. Can be left empty HelpLname - long name for the parser/command help argument. Leaving empty forces use of -h/--help when HelpDisabled is false NoExitOnHelp - defaults false, set true to not exit on help argument being parsed Should resolve all outstanding help argument issues. --- argparse.go | 75 ++++++++++++++++++- argparse_examples_test.go | 4 +- argparse_test.go | 28 +++++++ argument.go | 22 ++++-- command.go | 12 ++- .../help-argument-names.go | 20 +++++ examples/help-no-exit/help-no-exit.go | 21 ++++++ examples/no-help/no-help.go | 21 ++++++ 8 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 examples/help-argument-names/help-argument-names.go create mode 100644 examples/help-no-exit/help-no-exit.go create mode 100644 examples/no-help/no-help.go diff --git a/argparse.go b/argparse.go index cb59c6a..8e939fc 100644 --- a/argparse.go +++ b/argparse.go @@ -23,6 +23,7 @@ type Command struct { happened bool parent *Command HelpFunc func(c *Command, msg interface{}) string + exitOnHelp bool } // GetName exposes Command's name field @@ -97,6 +98,25 @@ type Options struct { Default interface{} } +// Settings are specific settings for a parser or command. They can be provided if necessary. +// Possible fields are: +// +// Settings.HelpDisabled - if true, does not creates a help argument for the Parser/Command. +// useful when a help argument should not be created. +// +// Settings.HelpSname - A string which will be used as the help argument short name. Can be left empty +// +// Settings.HelpLname - A string which will be used as the help argument long name. If left empty, +// -h and --help are used as the short and long names repectively +// +//Settings.NoExitOnHelp - if true, does call os.Exit when help arguments are parsed +type Settings struct { + HelpDisabled bool + HelpSname string + HelpLname string + NoExitOnHelp bool +} + // 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 @@ -109,7 +129,29 @@ func NewParser(name string, description string) *Parser { p.args = make([]*arg, 0) p.commands = make([]*Command, 0) - p.help() + p.help("h", "help") + p.exitOnHelp = true + p.HelpFunc = (*Command).Usage + + return p +} + +// NewParserWithSettings 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 +func NewParserWithSettings(name string, description string, settings Settings) *Parser { + p := &Parser{} + + p.name = name + p.description = description + + p.args = make([]*arg, 0) + p.commands = make([]*Command, 0) + + if !settings.HelpDisabled { + p.help(settings.HelpSname, settings.HelpLname) + } + p.exitOnHelp = !settings.NoExitOnHelp p.HelpFunc = (*Command).Usage return p @@ -129,7 +171,36 @@ func (o *Command) NewCommand(name string, description string) *Command { c.parsed = false c.parent = o - c.help() + c.help("h", "help") + c.exitOnHelp = true + + if o.commands == nil { + o.commands = make([]*Command, 0) + } + + o.commands = append(o.commands, c) + + return c +} + +// NewCommandWithSettings will create a sub-command and propagate all necessary fields. +// All commands are always at the beginning of the arguments. +// Parser can have commands and those commands can have sub-commands, +// which allows for very flexible workflow. +// All commands are considered as required and all commands can have their own argument set. +// Commands are processed Parser -> Command -> sub-Command. +// Arguments will be processed in order of sub-Command -> Command -> Parser. +func (o *Command) NewCommandWithSettings(name string, description string, settings Settings) *Command { + c := new(Command) + c.name = name + c.description = description + c.parsed = false + c.parent = o + + if !settings.HelpDisabled { + c.help(settings.HelpSname, settings.HelpLname) + } + c.exitOnHelp = !settings.NoExitOnHelp if o.commands == nil { o.commands = make([]*Command, 0) diff --git a/argparse_examples_test.go b/argparse_examples_test.go index b405ccd..1d38b6f 100644 --- a/argparse_examples_test.go +++ b/argparse_examples_test.go @@ -1,6 +1,8 @@ package argparse -import "fmt" +import ( + "fmt" +) func ExampleCommand_Help() { parser := NewParser("parser", "") diff --git a/argparse_test.go b/argparse_test.go index 412437a..17035c9 100644 --- a/argparse_test.go +++ b/argparse_test.go @@ -1186,3 +1186,31 @@ func TestNewParserHelpFuncDefault(t *testing.T) { t.Errorf("HelpFunc should default to Usage function") } } + +func TestNewParserWithSettingsHelpDisabled(t *testing.T) { + parser := NewParserWithSettings("parser", "", Settings{HelpDisabled: true}) + if len(parser.args) > 0 { + t.Errorf("Parser should not have any arguments") + } + if err := parser.Parse([]string{"parser", "-h"}); err == nil { + t.Errorf("Parsing should fail, help argument shouldn't exist") + } +} + +func TestNewParserWithSettingsHelpNames(t *testing.T) { + sname, lname := "x", "xyz" + parser := NewParserWithSettings("parser", "", Settings{HelpSname: sname, HelpLname: lname}) + if len(parser.args) != 1 { + t.Errorf("Parser should not have any arguments:\n%s", parser.Help(nil)) + } + arg := parser.args[0] + if _, ok := arg.result.(*help); !ok { + t.Errorf("Argument should be %T, is %T", help{}, arg.result) + } + if arg.sname != sname { + t.Errorf("Argument short name should be %s, is %s", sname, arg.sname) + } + if arg.lname != lname { + t.Errorf("Argument long name should be %s, is %s", lname, arg.lname) + } +} diff --git a/argument.go b/argument.go index cb92e9f..cf8bf95 100644 --- a/argument.go +++ b/argument.go @@ -42,14 +42,17 @@ func (o arg) GetLname() string { type help struct{} -func (o *arg) check(argument string) bool { - // Shortcut to showing help - if argument == "-h" || argument == "--help" { - helpText := o.parent.Help(nil) - fmt.Print(helpText) - os.Exit(0) - } +// HelpCalled error returned when parsing a help argument +// instead of exiting to prevent further parsing +type HelpCalled struct { + arg arg +} +func (hc *HelpCalled) Error() string { + return fmt.Sprintf("Command %s help argument parsed", hc.arg.parent.name) +} + +func (o *arg) check(argument string) bool { // Check for long name only if not empty if o.lname != "" { // If argument begins with "--" and next is not "-" then it is a long name @@ -137,7 +140,10 @@ func (o *arg) parse(args []string) error { case *help: helpText := o.parent.Help(nil) fmt.Print(helpText) - os.Exit(0) + if o.parent.exitOnHelp { + os.Exit(0) + } + return &HelpCalled{*o} case *bool: *o.result.(*bool) = true o.parsed = true diff --git a/command.go b/command.go index 1053301..cccef94 100644 --- a/command.go +++ b/command.go @@ -4,13 +4,17 @@ import ( "fmt" ) -func (o *Command) help() { +func (o *Command) help(sname, lname string) { result := &help{} + if lname == "" { + sname, lname = "h", "help" + } + a := &arg{ - result: &result, - sname: "h", - lname: "help", + result: result, + sname: sname, + lname: lname, size: 1, opts: &Options{Help: "Print help information"}, unique: true, diff --git a/examples/help-argument-names/help-argument-names.go b/examples/help-argument-names/help-argument-names.go new file mode 100644 index 0000000..d47edc1 --- /dev/null +++ b/examples/help-argument-names/help-argument-names.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + + "github.com/akamensky/argparse" +) + +func main() { + // Create Parser Settings + settings := argparse.Settings{HelpSname: "e", HelpLname: "example"} + // Create new parser object + parser := argparse.NewParserWithSettings("help", "Demonstrates changing the help argument names", settings) + // Create string flag + parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) + // Create string flag + parser.Int("i", "int", &argparse.Options{Required: false, Help: "Integer argument example"}) + // Use the help function + fmt.Print(parser.Parse([]string{"parser", "-e"})) +} diff --git a/examples/help-no-exit/help-no-exit.go b/examples/help-no-exit/help-no-exit.go new file mode 100644 index 0000000..a236854 --- /dev/null +++ b/examples/help-no-exit/help-no-exit.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + + "github.com/akamensky/argparse" +) + +func main() { + // Create Parser Settings + settings := argparse.Settings{NoExitOnHelp: true} + // Create new parser object + parser := argparse.NewParserWithSettings("help", "Demonstrates changing the help argument names", settings) + // Create string flag + parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) + // Create string flag + parser.Int("i", "int", &argparse.Options{Required: false, Help: "Integer argument example"}) + // Use the help function + fmt.Println(parser.Parse([]string{"parser", "-h"})) + fmt.Println("Didn't exit, still printing") +} diff --git a/examples/no-help/no-help.go b/examples/no-help/no-help.go new file mode 100644 index 0000000..f66fb8c --- /dev/null +++ b/examples/no-help/no-help.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + + "github.com/akamensky/argparse" +) + +func main() { + // Create Parser Settings + settings := argparse.Settings{HelpDisabled: true} + // Create new parser object + parser := argparse.NewParserWithSettings("help", "Demonstrates disabing the help arguments", settings) + // Create string flag + parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) + // Create string flag + parser.Int("i", "int", &argparse.Options{Required: false, Help: "Integer argument example"}) + + // parsing for -h fails + fmt.Println(parser.Parse([]string{"parser", "-h", "--help", "-s", "testing", "-i", "5"})) +} From d5a30b01ade29c11889db5943251438a97de72c3 Mon Sep 17 00:00:00 2001 From: Densest Void Date: Sun, 8 Dec 2019 19:00:08 -0500 Subject: [PATCH 2/4] Finishing Issue #29 Fixed merge conflict error due to check function return type change confusion. --- argument.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/argument.go b/argument.go index 01d6f8f..e406efc 100644 --- a/argument.go +++ b/argument.go @@ -52,7 +52,11 @@ func (hc *HelpCalled) Error() string { return fmt.Sprintf("Command %s help argument parsed", hc.arg.parent.name) } -func (o *arg) check(argument string) bool { +//Check if argumet present. +//For args with size 1 (Flag,FlagCounter) multiple shorthand in one argument are allowed, +//so check - returns the number of occurrences. +//For other args check - returns 1 if occured or 0 in no +func (o *arg) check(argument string) int { // Check for long name only if not empty if o.lname != "" { // If argument begins with "--" and next is not "-" then it is a long name @@ -70,10 +74,8 @@ func (o *arg) check(argument string) bool { if o.size == 1 { return strings.Count(argument[1:], o.sname) // For all other types it must be separate argument - } else { - if argument[1:] == o.sname { - return 1 - } + } else if argument[1:] == o.sname { + return 1 } } } From f720dad9b27700c625403f089aa4446a8da0d6e4 Mon Sep 17 00:00:00 2001 From: Densest Void Date: Sat, 25 Jan 2020 16:36:38 -0500 Subject: [PATCH 3/4] Updated Settings Object to multiple function calls Added functions: DisableHelp SetHelp ExitOnHelp Added Command.exitOnHelp Added more tests to increase code coverage --- argparse.go | 84 ++------- argparse_test.go | 167 +++++++++++++++++- argument.go | 23 +-- .../help-argument-names.go | 5 +- examples/help-no-exit/help-no-exit.go | 5 +- examples/no-help/no-help.go | 5 +- 6 files changed, 194 insertions(+), 95 deletions(-) diff --git a/argparse.go b/argparse.go index 53bff65..d68269c 100644 --- a/argparse.go +++ b/argparse.go @@ -98,25 +98,6 @@ type Options struct { Default interface{} } -// Settings are specific settings for a parser or command. They can be provided if necessary. -// Possible fields are: -// -// Settings.HelpDisabled - if true, does not creates a help argument for the Parser/Command. -// useful when a help argument should not be created. -// -// Settings.HelpSname - A string which will be used as the help argument short name. Can be left empty -// -// Settings.HelpLname - A string which will be used as the help argument long name. If left empty, -// -h and --help are used as the short and long names repectively -// -//Settings.NoExitOnHelp - if true, does call os.Exit when help arguments are parsed -type Settings struct { - HelpDisabled bool - HelpSname string - HelpLname string - NoExitOnHelp bool -} - // 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 @@ -136,27 +117,6 @@ func NewParser(name string, description string) *Parser { return p } -// NewParserWithSettings 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 -func NewParserWithSettings(name string, description string, settings Settings) *Parser { - p := &Parser{} - - p.name = name - p.description = description - - p.args = make([]*arg, 0) - p.commands = make([]*Command, 0) - - if !settings.HelpDisabled { - p.help(settings.HelpSname, settings.HelpLname) - } - p.exitOnHelp = !settings.NoExitOnHelp - p.HelpFunc = (*Command).Usage - - return p -} - // NewCommand will create a sub-command and propagate all necessary fields. // All commands are always at the beginning of the arguments. // Parser can have commands and those commands can have sub-commands, @@ -170,9 +130,7 @@ func (o *Command) NewCommand(name string, description string) *Command { c.description = description c.parsed = false c.parent = o - - c.help("h", "help") - c.exitOnHelp = true + c.exitOnHelp = o.exitOnHelp if o.commands == nil { o.commands = make([]*Command, 0) @@ -183,32 +141,28 @@ func (o *Command) NewCommand(name string, description string) *Command { return c } -// NewCommandWithSettings will create a sub-command and propagate all necessary fields. -// All commands are always at the beginning of the arguments. -// Parser can have commands and those commands can have sub-commands, -// which allows for very flexible workflow. -// All commands are considered as required and all commands can have their own argument set. -// Commands are processed Parser -> Command -> sub-Command. -// Arguments will be processed in order of sub-Command -> Command -> Parser. -func (o *Command) NewCommandWithSettings(name string, description string, settings Settings) *Command { - c := new(Command) - c.name = name - c.description = description - c.parsed = false - c.parent = o - - if !settings.HelpDisabled { - c.help(settings.HelpSname, settings.HelpLname) +// DisableHelp removes any help arguments from the commands list of arguments +// This prevents prevents help from being parsed or invoked from the argument list +func (o *Parser) DisableHelp() { + for i, arg := range o.args { + if _, ok := arg.result.(*help); ok { + o.args = append(o.args[:i], o.args[i+1:]...) + } } - c.exitOnHelp = !settings.NoExitOnHelp +} - if o.commands == nil { - o.commands = make([]*Command, 0) +// ExitOnHelp sets the exitOnHelp variable of Parser +func (o *Command) ExitOnHelp(b bool) { + o.exitOnHelp = b + for _, c := range o.commands { + c.ExitOnHelp(b) } +} - o.commands = append(o.commands, c) - - return c +// SetHelp removes the previous help argument, and creates a new one with the desired sname/lname +func (o *Parser) SetHelp(sname, lname string) { + o.DisableHelp() + o.help(sname, lname) } // Flag Creates new flag type of argument, which is boolean value showing if argument was provided or not. diff --git a/argparse_test.go b/argparse_test.go index 42c0e4d..423b2d5 100644 --- a/argparse_test.go +++ b/argparse_test.go @@ -1877,28 +1877,97 @@ func TestUsageStringer(t *testing.T) { } } -func TestNewParserHelpFuncDefault(t *testing.T) { +func TestParserHelpFuncDefault(t *testing.T) { parser := NewParser("parser", "") if parser.HelpFunc == nil || parser.Help(nil) != parser.Usage(nil) { t.Errorf("HelpFunc should default to Usage function") } } -func TestNewParserWithSettingsHelpDisabled(t *testing.T) { - parser := NewParserWithSettings("parser", "", Settings{HelpDisabled: true}) +func TestCommandHelpFuncDefault(t *testing.T) { + parser := NewParser("parser", "") + command := parser.NewCommand("command", "") + if command.HelpFunc != nil { + t.Errorf("HelpFunc should default to Usage function") + } +} + +func TestCommandHelpFuncDefaultToParent(t *testing.T) { + parser := NewParser("parser", "") + command := parser.NewCommand("command", "") + + parser.HelpFunc = func(c *Command, msg interface{}) string { + return "testing" + } + + if command.Help(nil) == command.Usage(nil) || command.Help(nil) != parser.Help(nil) { + t.Errorf("command HelpFunc should default to parent function") + } +} + +func TestParserExitOnHelpTrue(t *testing.T) { + exited := false + exit = func(n int) { + exited = true + } + + parser := NewParser("parser", "") + + print = func(...interface{}) (int, error) { + return 0, nil + } + + if err := parser.Parse([]string{"parser", "-h"}); err == nil { + if !exited { + t.Errorf("Parsing help should have invoked os.Exit") + } + } else { + t.Error(err) + } +} + +func TestParserExitOnHelpFalse(t *testing.T) { + exited := false + exit = func(n int) { + exited = true + } + + parser := NewParser("parser", "") + parser.ExitOnHelp(false) + + print = func(...interface{}) (int, error) { + return 0, nil + } + + if err := parser.Parse([]string{"parser", "-h"}); exited { + t.Errorf("Parsing help should not have invoked os.Exit") + } else if err != nil { + t.Error(err) + } +} + +func TestParserDisableHelp(t *testing.T) { + parser := NewParser("parser", "") + parser.DisableHelp() if len(parser.args) > 0 { t.Errorf("Parser should not have any arguments") } + + print = func(...interface{}) (int, error) { + return 0, nil + } + if err := parser.Parse([]string{"parser", "-h"}); err == nil { t.Errorf("Parsing should fail, help argument shouldn't exist") } } -func TestNewParserWithSettingsHelpNames(t *testing.T) { +func TestParserSetHelp(t *testing.T) { sname, lname := "x", "xyz" - parser := NewParserWithSettings("parser", "", Settings{HelpSname: sname, HelpLname: lname}) + parser := NewParser("parser", "") + parser.SetHelp(sname, lname) if len(parser.args) != 1 { - t.Errorf("Parser should not have any arguments:\n%s", parser.Help(nil)) + t.Errorf("Parser should have one argument:\n%s", parser.Help(nil)) } arg := parser.args[0] if _, ok := arg.result.(*help); !ok { @@ -1911,3 +1980,89 @@ func TestNewParserWithSettingsHelpNames(t *testing.T) { t.Errorf("Argument long name should be %s, is %s", lname, arg.lname) } } + +func TestCommandExitOnHelpTrue(t *testing.T) { + exited := false + exit = func(n int) { + exited = true + } + + parser := NewParser("parser", "") + parser.NewCommand("command", "") + + print = func(...interface{}) (int, error) { + return 0, nil + } + + if err := parser.Parse([]string{"parser", "command", "-h"}); exited { + if err != nil { + t.Error(err) + } + } else { + t.Errorf("Parsing help should have invoked os.Exit") + } +} + +func TestCommandExitOnHelpFalse(t *testing.T) { + exited := false + exit = func(n int) { + exited = true + } + + parser := NewParser("parser", "") + parser.NewCommand("command", "") + parser.ExitOnHelp(false) + + print = func(...interface{}) (int, error) { + return 0, nil + } + + if err := parser.Parse([]string{"parser", "command", "-h"}); exited { + t.Error("Parsing help should not have exited") + } else if err != nil { + t.Error(err) + } +} + +func TestCommandDisableHelp(t *testing.T) { + parser := NewParser("parser", "") + parser.NewCommand("command", "") + parser.DisableHelp() + if len(parser.args) > 0 { + t.Errorf("Parser should not have any arguments") + } + + print = func(...interface{}) (int, error) { + return 0, nil + } + + if err := parser.Parse([]string{"parser", "command", "-h"}); err == nil { + t.Errorf("Parsing should fail, help argument shouldn't exist") + } +} + +func TestCommandHelpInheritance(t *testing.T) { + parser := NewParser("parser", "") + command := parser.NewCommand("command", "") + parser.ExitOnHelp(false) + + if command.exitOnHelp != false { + t.Errorf("Command should inherit exitOnHelp from parent, even after creation") + } +} + +func TestCommandHelpSetSnameOnly(t *testing.T) { + parser := NewParser("parser", "") + parser.SetHelp("q", "") + + arg := parser.args[0] + + _, ok := arg.result.(*help) + if !ok { + t.Error("Argument should be of help type") + } + + if arg.sname != "h" || arg.lname != "help" { + t.Error("Help arugment names should have defaulted") + } +} diff --git a/argument.go b/argument.go index e406efc..aab9911 100644 --- a/argument.go +++ b/argument.go @@ -42,17 +42,7 @@ func (o arg) GetLname() string { type help struct{} -// HelpCalled error returned when parsing a help argument -// instead of exiting to prevent further parsing -type HelpCalled struct { - arg arg -} - -func (hc *HelpCalled) Error() string { - return fmt.Sprintf("Command %s help argument parsed", hc.arg.parent.name) -} - -//Check if argumet present. +//Check if argument present. //For args with size 1 (Flag,FlagCounter) multiple shorthand in one argument are allowed, //so check - returns the number of occurrences. //For other args check - returns 1 if occured or 0 in no @@ -120,6 +110,11 @@ func (o *arg) reduce(position int, args *[]string) { } } +// To overwrite while testing +// Possibly extend to allow user overriding +var exit func(int) = os.Exit +var print func(...interface{}) (int, error) = fmt.Println + func (o *arg) parse(args []string, argCount int) error { // If unique do not allow more than one time if o.unique && (o.parsed || argCount > 1) { @@ -136,12 +131,10 @@ func (o *arg) parse(args []string, argCount int) error { switch o.result.(type) { case *help: - helpText := o.parent.Help(nil) - fmt.Print(helpText) + print(o.parent.Help(nil)) if o.parent.exitOnHelp { - os.Exit(0) + exit(0) } - return &HelpCalled{*o} //data of bool type is for Flag argument case *bool: *o.result.(*bool) = true diff --git a/examples/help-argument-names/help-argument-names.go b/examples/help-argument-names/help-argument-names.go index d47edc1..e8151d0 100644 --- a/examples/help-argument-names/help-argument-names.go +++ b/examples/help-argument-names/help-argument-names.go @@ -7,10 +7,9 @@ import ( ) func main() { - // Create Parser Settings - settings := argparse.Settings{HelpSname: "e", HelpLname: "example"} // Create new parser object - parser := argparse.NewParserWithSettings("help", "Demonstrates changing the help argument names", settings) + parser := argparse.NewParser("help", "Demonstrates changing the help argument names") + parser.SetHelp("e", "example") // Create string flag parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) // Create string flag diff --git a/examples/help-no-exit/help-no-exit.go b/examples/help-no-exit/help-no-exit.go index a236854..c9eb79e 100644 --- a/examples/help-no-exit/help-no-exit.go +++ b/examples/help-no-exit/help-no-exit.go @@ -7,10 +7,9 @@ import ( ) func main() { - // Create Parser Settings - settings := argparse.Settings{NoExitOnHelp: true} // Create new parser object - parser := argparse.NewParserWithSettings("help", "Demonstrates changing the help argument names", settings) + parser := argparse.NewParser("help", "Demonstrates changing the help argument names") + parser.ExitOnHelp = false // Create string flag parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) // Create string flag diff --git a/examples/no-help/no-help.go b/examples/no-help/no-help.go index f66fb8c..422918b 100644 --- a/examples/no-help/no-help.go +++ b/examples/no-help/no-help.go @@ -7,10 +7,9 @@ import ( ) func main() { - // Create Parser Settings - settings := argparse.Settings{HelpDisabled: true} // Create new parser object - parser := argparse.NewParserWithSettings("help", "Demonstrates disabing the help arguments", settings) + parser := argparse.NewParser("help", "Demonstrates disabing the help arguments") + parser.DisableHelp() // Create string flag parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) // Create string flag From 44b8b28b40564d7f42f9d19cd3f47e6bbd2b133a Mon Sep 17 00:00:00 2001 From: Densest Void Date: Sat, 25 Jan 2020 17:01:26 -0500 Subject: [PATCH 4/4] Updated no help example --- examples/help-no-exit/help-no-exit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/help-no-exit/help-no-exit.go b/examples/help-no-exit/help-no-exit.go index c9eb79e..a5b5c55 100644 --- a/examples/help-no-exit/help-no-exit.go +++ b/examples/help-no-exit/help-no-exit.go @@ -9,7 +9,7 @@ import ( func main() { // Create new parser object parser := argparse.NewParser("help", "Demonstrates changing the help argument names") - parser.ExitOnHelp = false + parser.ExitOnHelp(false) // Create string flag parser.String("s", "string", &argparse.Options{Required: false, Help: "String argument example"}) // Create string flag