mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
Show help text when no args are given (#573)
* show help text when no args are given Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * repurpose the input args validation function Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * ensure app does not check for update in cli tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
+17
-10
@@ -50,23 +50,20 @@ func runSyftInDocker(t testing.TB, env map[string]string, image string, args ...
|
||||
|
||||
func runSyft(t testing.TB, env map[string]string, args ...string) (*exec.Cmd, string, string) {
|
||||
cmd := getSyftCommand(t, args...)
|
||||
if env != nil {
|
||||
env["SYFT_CHECK_FOR_APP_UPDATE"] = "false"
|
||||
if env == nil {
|
||||
env = make(map[string]string)
|
||||
}
|
||||
|
||||
// we should not have tests reaching out for app update checks
|
||||
env["SYFT_CHECK_FOR_APP_UPDATE"] = "false"
|
||||
|
||||
stdout, stderr := runCommand(cmd, env)
|
||||
return cmd, stdout, stderr
|
||||
}
|
||||
|
||||
func runCommand(cmd *exec.Cmd, env map[string]string) (string, string) {
|
||||
if env != nil {
|
||||
var envList []string
|
||||
for key, val := range env {
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", key, val))
|
||||
}
|
||||
cmd.Env = envList
|
||||
cmd.Env = append(os.Environ(), envMapToSlice(env)...)
|
||||
}
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
@@ -78,6 +75,16 @@ func runCommand(cmd *exec.Cmd, env map[string]string) (string, string) {
|
||||
return stdout.String(), stderr.String()
|
||||
}
|
||||
|
||||
func envMapToSlice(env map[string]string) (envList []string) {
|
||||
for key, val := range env {
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
envList = append(envList, fmt.Sprintf("%s=%s", key, val))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getSyftCommand(t testing.TB, args ...string) *exec.Cmd {
|
||||
return exec.Command(getSyftBinaryLocation(t), args...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user