From 314c9b86c2348847b079ae7e841f876556753062 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 9 Jul 2023 16:11:47 +0900 Subject: [PATCH] add TestHelpCommandExecutedWithPersistentRequiredFlags --- command_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/command_test.go b/command_test.go index 0212f5ae..ac435e09 100644 --- a/command_test.go +++ b/command_test.go @@ -885,6 +885,18 @@ func TestHelpCommandExecuted(t *testing.T) { checkStringContains(t, output, rootCmd.Long) } +func TestHelpCommandExecutedWithPersistentRequiredFlags(t *testing.T) { + rootCmd := &Command{Use: "root", Run: emptyRun} + rootCmd.PersistentFlags().Bool("foo", false, "") + childCmd := &Command{Use: "child", Run: emptyRun} + rootCmd.AddCommand(childCmd) + assertNoErr(t, rootCmd.MarkPersistentFlagRequired("foo")) + + if _, err := executeCommand(rootCmd, "help"); err != nil { + t.Errorf("unexpected error: %v", err) + } +} + func TestHelpCommandExecutedOnChild(t *testing.T) { rootCmd := &Command{Use: "root", Run: emptyRun} childCmd := &Command{Use: "child", Long: "Long description", Run: emptyRun}