From 2299852c3c3512dafac738a10847da3bb3699b62 Mon Sep 17 00:00:00 2001 From: Lynn Cyrin Date: Thu, 18 Jul 2019 00:47:18 -0700 Subject: [PATCH] cleanup subcommand and specs --- app.go | 4 ++-- app_test.go | 17 +---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/app.go b/app.go index 52c2d85..485c92b 100644 --- a/app.go +++ b/app.go @@ -327,7 +327,6 @@ func (a *App) RunAsSubcommand(ctx *Context) (err 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) if nerr != nil { @@ -341,8 +340,9 @@ func (a *App) RunAsSubcommand(ctx *Context) (err error) { return nerr } + cerr := checkRequiredFlags(a.Flags, set) if cerr != nil { - ShowAppHelp(context) + ShowSubcommandHelp(context) return cerr } diff --git a/app_test.go b/app_test.go index 28c4afc..660d238 100644 --- a/app_test.go +++ b/app_test.go @@ -890,22 +890,13 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) { expectedAnError bool expectedFlagErrorPrinter bool }{ - { - // expectations: - // - empty input shows the help message - // - empty input explicitly does not error - testCase: "empty_input", - appRunInput: []string{""}, - expectedHelpPrinter: true, - expectedAnError: false, // explicit false for readability (this is the default value) - }, { // expectations: // - empty input, when a required flag is present, shows the help message // - empty input, when a required flag is present, errors // - empty input, when a required flag is present, show the flag error message testCase: "empty_input_with_required_flag", - appRunInput: []string{""}, + appRunInput: []string{"command"}, flags: []Flag{StringFlag{Name: "requiredFlag", Required: true}}, expectedHelpPrinter: true, expectedAnError: true, @@ -966,12 +957,6 @@ func TestRequiredFlagAppRunBehavior(t *testing.T) { Command{ Name: "command", Flags: test.flags, - Subcommands: []Command{ - Command{ - Name: "subcommand", - Flags: test.flags, - }, - }, }, }