From 7223d7d3c1b72585c0c991ae30472a57359020e4 Mon Sep 17 00:00:00 2001 From: Timo Tietavainen Date: Thu, 25 Nov 2021 19:44:53 +0200 Subject: [PATCH] Show help when no sdlcli arguments Implement showing of the help text also when sdlcli tool is called without any arguments. Issue-Id: RIC-113 Signed-off-by: Timo Tietavainen Change-Id: I6ebd9844fe09debeeb24946ba55ebfb2d7b807c3 --- internal/cli/root.go | 1 + internal/cli/root_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/internal/cli/root.go b/internal/cli/root.go index c5cf5ac..502c42b 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -36,6 +36,7 @@ func newRootCmd() *cobra.Command { Short: "Shared Data Layer (SDL) troubleshooting command line tool", Long: `Shared Data Layer (SDL) troubleshooting command line tool`, Run: func(cmd *cobra.Command, args []string) { + cmd.Help() }, } } diff --git a/internal/cli/root_test.go b/internal/cli/root_test.go index 947a6c0..74124f4 100644 --- a/internal/cli/root_test.go +++ b/internal/cli/root_test.go @@ -39,6 +39,7 @@ func TestCliShowsHelp(t *testing.T) { expErr error expOutput string }{ + {args: "", expErr: expOkErr, expOutput: expHelp}, {args: "-h", expErr: expOkErr, expOutput: expHelp}, {args: "--help", expErr: expOkErr, expOutput: expHelp}, {args: "--some-unknown-flag", expErr: expNokErr, expOutput: expHelp}, @@ -50,6 +51,7 @@ func TestCliShowsHelp(t *testing.T) { cmd.SetOut(buf) cmd.SetErr(buf) cmd.SetArgs([]string{test.args}) + err := cmd.Execute() result := buf.String() assert.Equal(t, test.expErr, err) -- 2.16.6