diff --git a/cmd/packages.go b/cmd/packages.go index c0769dc642c..32cd3474afe 100644 --- a/cmd/packages.go +++ b/cmd/packages.go @@ -47,7 +47,7 @@ const ( var ( packagesPresenterOpt packages.PresenterOption - packagesArgs = cobra.MinimumNArgs(1) + packagesArgs = cobra.MaximumNArgs(1) packagesCmd = &cobra.Command{ Use: "packages [SOURCE]", Short: "Generate a package SBOM", @@ -65,8 +65,7 @@ var ( if err != nil { return err } - // silently exit - return fmt.Errorf("") + return fmt.Errorf("an image/directory argument is required") } // set the presenter diff --git a/cmd/power_user.go b/cmd/power_user.go index fb2082cd2a3..e70cab218c8 100644 --- a/cmd/power_user.go +++ b/cmd/power_user.go @@ -34,11 +34,19 @@ var powerUserCmd = &cobra.Command{ "appName": internal.ApplicationName, "command": "power-user", }), - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), Hidden: true, SilenceUsage: true, SilenceErrors: true, PreRunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + err := cmd.Help() + if err != nil { + return err + } + return fmt.Errorf("an image/directory argument is required") + } + if appConfig.Dev.ProfileCPU && appConfig.Dev.ProfileMem { return fmt.Errorf("cannot profile CPU and memory simultaneously") } diff --git a/test/cli/packages_cmd_test.go b/test/cli/packages_cmd_test.go index 5ca02b05ce9..f9a0ecf7604 100644 --- a/test/cli/packages_cmd_test.go +++ b/test/cli/packages_cmd_test.go @@ -16,6 +16,15 @@ func TestPackagesCmdFlags(t *testing.T) { env map[string]string assertions []traitAssertion }{ + { + name: "no-args-shows-help", + args: []string{"packages"}, + assertions: []traitAssertion{ + assertInOutput("an image/directory argument is required"), // specific error that should be shown + assertInOutput("Generate a packaged-based Software Bill Of Materials"), // excerpt from help description + assertFailingReturnCode, + }, + }, { name: "json-output-flag", args: []string{"packages", "-o", "json", request}, diff --git a/test/cli/power_user_cmd_test.go b/test/cli/power_user_cmd_test.go index e5bb95a4665..71445be626e 100644 --- a/test/cli/power_user_cmd_test.go +++ b/test/cli/power_user_cmd_test.go @@ -12,6 +12,15 @@ func TestPowerUserCmdFlags(t *testing.T) { env map[string]string assertions []traitAssertion }{ + { + name: "no-args-shows-help", + args: []string{"power-user"}, + assertions: []traitAssertion{ + assertInOutput("an image/directory argument is required"), // specific error that should be shown + assertInOutput("Run bulk operations on container images"), // excerpt from help description + assertFailingReturnCode, + }, + }, { name: "json-output-flag-fails", args: []string{"power-user", "-o", "json", "docker-archive:" + getFixtureImage(t, "image-pkg-coverage")},