From 163f24751936fa434cde04210cc00dbe1b40c6ba Mon Sep 17 00:00:00 2001 From: OneOfOne Date: Tue, 29 Aug 2017 17:26:30 +0200 Subject: [PATCH 1/3] lint + DefaultCommand --- app.go | 10 +++++++++- command.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index fca28c7..2638fed 100644 --- a/app.go +++ b/app.go @@ -212,7 +212,7 @@ func (a *App) Run(arguments []string) (err error) { if err != nil { if a.OnUsageError != nil { - err := a.OnUsageError(context, err, false) + err = a.OnUsageError(context, err, false) HandleExitCoder(err) return err } @@ -480,3 +480,11 @@ func (a *Author) String() string { return fmt.Sprintf("%v%v", a.Name, e) } + +// DefaultAppComplete returns an ActionFunc to run a default command if non were passed. +// Usage: `app.Action = DefaultCommand("command")` +func DefaultCommand(name string) ActionFunc { + return func(ctx *Context) error { + return ctx.App.Command(name).Run(ctx) + } +} diff --git a/command.go b/command.go index 4f0d142..05093b8 100644 --- a/command.go +++ b/command.go @@ -122,7 +122,7 @@ func (c *Command) Run(ctx *Context) (err error) { if err != nil { if c.OnUsageError != nil { - err := c.OnUsageError(context, err, false) + err = c.OnUsageError(context, err, false) HandleExitCoder(err) return err } From b7ab5b0c4823f439bba54438246d4be1bde49864 Mon Sep 17 00:00:00 2001 From: OneOfOne Date: Thu, 31 Aug 2017 00:26:52 +0200 Subject: [PATCH 2/3] don't add -- prefix if we manually specify one --- flag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flag.go b/flag.go index d5ab42e..9e71a51 100644 --- a/flag.go +++ b/flag.go @@ -778,7 +778,7 @@ func visibleFlags(fl []Flag) []Flag { func prefixFor(name string) (prefix string) { if len(name) == 1 { prefix = "-" - } else { + } else if name[0] != '-' { prefix = "--" } From 10c9734c5e7553418edf1cd20685d2e660f366f1 Mon Sep 17 00:00:00 2001 From: OneOfOne Date: Tue, 23 Jan 2018 19:45:38 +0200 Subject: [PATCH 3/3] notes --- app.go | 2 +- flag.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 2638fed..4c073c5 100644 --- a/app.go +++ b/app.go @@ -482,7 +482,7 @@ func (a *Author) String() string { } // DefaultAppComplete returns an ActionFunc to run a default command if non were passed. -// Usage: `app.Action = DefaultCommand("command")` +// Usage: `app.Action = cli.DefaultCommand("command")` func DefaultCommand(name string) ActionFunc { return func(ctx *Context) error { return ctx.App.Command(name).Run(ctx) diff --git a/flag.go b/flag.go index 9e71a51..d5ab42e 100644 --- a/flag.go +++ b/flag.go @@ -778,7 +778,7 @@ func visibleFlags(fl []Flag) []Flag { func prefixFor(name string) (prefix string) { if len(name) == 1 { prefix = "-" - } else if name[0] != '-' { + } else { prefix = "--" }