-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required flags #155
Required flags #155
Changes from 3 commits
7e05320
73e64a1
4b2fcdb
8f1fb06
cbd9529
e67e05f
6023f37
145da32
b5844af
a6482d2
aba73ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,14 +87,25 @@ func (a *App) Run(arguments []string) error { | |
set.SetOutput(ioutil.Discard) | ||
err := set.Parse(arguments[1:]) | ||
nerr := normalizeFlags(a.Flags, set) | ||
cerr := checkRequiredFlags(a.Flags, set) | ||
|
||
context := NewContext(a, set, set) | ||
|
||
if nerr != nil { | ||
fmt.Println(nerr) | ||
context := NewContext(a, set, set) | ||
fmt.Println("") | ||
ShowAppHelp(context) | ||
fmt.Println("") | ||
return nerr | ||
} | ||
context := NewContext(a, set, set) | ||
|
||
if cerr != nil { | ||
fmt.Println(cerr) | ||
fmt.Println("") | ||
ShowAppHelp(context) | ||
fmt.Println("") | ||
return cerr | ||
} | ||
|
||
if err != nil { | ||
fmt.Printf("Incorrect Usage.\n\n") | ||
|
@@ -164,10 +175,13 @@ func (a *App) RunAsSubcommand(ctx *Context) error { | |
set.SetOutput(ioutil.Discard) | ||
err := set.Parse(ctx.Args().Tail()) | ||
nerr := normalizeFlags(a.Flags, set) | ||
cerr := checkRequiredFlags(a.Flags, set) | ||
|
||
context := NewContext(a, set, ctx.globalSet) | ||
|
||
if nerr != nil { | ||
fmt.Println(nerr) | ||
fmt.Println("") | ||
if len(a.Commands) > 0 { | ||
ShowSubcommandHelp(context) | ||
} else { | ||
|
@@ -177,6 +191,20 @@ func (a *App) RunAsSubcommand(ctx *Context) error { | |
return nerr | ||
} | ||
|
||
if cerr != nil { | ||
fmt.Println(cerr) | ||
fmt.Println("") | ||
if len(a.Commands) > 0 { | ||
ShowSubcommandHelp(context) | ||
fmt.Println("subcommands") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this here? |
||
} else { | ||
ShowCommandHelp(ctx, context.Args().First()) | ||
fmt.Println("commands") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this here as well? |
||
} | ||
fmt.Println("") | ||
return cerr | ||
} | ||
|
||
if err != nil { | ||
fmt.Printf("Incorrect Usage.\n\n") | ||
ShowSubcommandHelp(context) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,16 @@ func (c Command) Run(ctx *Context) error { | |
fmt.Println("") | ||
return nerr | ||
} | ||
|
||
cerr := checkRequiredFlags(c.Flags, set) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with respect to DRYing. |
||
if cerr != nil { | ||
fmt.Println(cerr) | ||
fmt.Println("") | ||
ShowCommandHelp(ctx, c.Name) | ||
fmt.Println("") | ||
return cerr | ||
} | ||
|
||
context := NewContext(ctx.App, set, ctx.globalSet) | ||
|
||
if checkCommandCompletions(context, c.Name) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to DRY this up by combining with the above conditional. The only thing that differs is which error you print.