mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 18:46:41 +01:00
add help message when no arguments are provided (#455)
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
2de56c0749
commit
ecf4e5546a
@ -47,7 +47,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
packagesPresenterOpt packages.PresenterOption
|
packagesPresenterOpt packages.PresenterOption
|
||||||
packagesArgs = cobra.MinimumNArgs(1)
|
packagesArgs = cobra.MaximumNArgs(1)
|
||||||
packagesCmd = &cobra.Command{
|
packagesCmd = &cobra.Command{
|
||||||
Use: "packages [SOURCE]",
|
Use: "packages [SOURCE]",
|
||||||
Short: "Generate a package SBOM",
|
Short: "Generate a package SBOM",
|
||||||
@ -65,8 +65,7 @@ var (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// silently exit
|
return fmt.Errorf("an image/directory argument is required")
|
||||||
return fmt.Errorf("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the presenter
|
// set the presenter
|
||||||
|
|||||||
@ -34,11 +34,19 @@ var powerUserCmd = &cobra.Command{
|
|||||||
"appName": internal.ApplicationName,
|
"appName": internal.ApplicationName,
|
||||||
"command": "power-user",
|
"command": "power-user",
|
||||||
}),
|
}),
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
Hidden: true,
|
Hidden: true,
|
||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
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 {
|
if appConfig.Dev.ProfileCPU && appConfig.Dev.ProfileMem {
|
||||||
return fmt.Errorf("cannot profile CPU and memory simultaneously")
|
return fmt.Errorf("cannot profile CPU and memory simultaneously")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,15 @@ func TestPackagesCmdFlags(t *testing.T) {
|
|||||||
env map[string]string
|
env map[string]string
|
||||||
assertions []traitAssertion
|
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",
|
name: "json-output-flag",
|
||||||
args: []string{"packages", "-o", "json", request},
|
args: []string{"packages", "-o", "json", request},
|
||||||
|
|||||||
@ -12,6 +12,15 @@ func TestPowerUserCmdFlags(t *testing.T) {
|
|||||||
env map[string]string
|
env map[string]string
|
||||||
assertions []traitAssertion
|
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",
|
name: "json-output-flag-fails",
|
||||||
args: []string{"power-user", "-o", "json", "docker-archive:" + getFixtureImage(t, "image-pkg-coverage")},
|
args: []string{"power-user", "-o", "json", "docker-archive:" + getFixtureImage(t, "image-pkg-coverage")},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user