diff --git a/pkg/action/suite_test.go b/pkg/action/suite_test.go index 342a2bd0a..229bd0fa3 100644 --- a/pkg/action/suite_test.go +++ b/pkg/action/suite_test.go @@ -31,5 +31,5 @@ import ( func TestCreate(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Create Suite") + RunSpecs(t, "Action Suite") } diff --git a/pkg/cmd/cli.go b/pkg/cmd/cli.go index d7ef0c4a1..fab7047ec 100644 --- a/pkg/cmd/cli.go +++ b/pkg/cmd/cli.go @@ -21,7 +21,6 @@ package cmd import ( "fmt" - "os" "strings" diff --git a/pkg/types/types.go b/pkg/types/types.go index 9769ad7e9..694fa7f9d 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -42,6 +42,9 @@ const ( // CliChartsCache defines kbcli charts cache dir name CliChartsCache = "charts" + // CliLogDir defines kbcli log dir name + CliLogDir = "logs" + // CliHomeEnv defines kbcli home system env CliHomeEnv = "KBCLI_HOME" diff --git a/pkg/util/log.go b/pkg/util/log.go index 8d3501519..57022243f 100644 --- a/pkg/util/log.go +++ b/pkg/util/log.go @@ -64,7 +64,7 @@ func EnableLogToFile(fs *pflag.FlagSet) error { } func getCliLogFile() (string, error) { - homeDir, err := GetCliHomeDir() + homeDir, err := GetCliLogDir() if err != nil { return "", err } diff --git a/pkg/util/util.go b/pkg/util/util.go index e2b209b33..29a47626c 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -106,6 +106,21 @@ func GetCliHomeDir() (string, error) { return cliHome, nil } +// GetCliLogDir returns kbcli log dir +func GetCliLogDir() (string, error) { + cliHome, err := GetCliHomeDir() + if err != nil { + return "", err + } + logDir := filepath.Join(cliHome, types.CliLogDir) + if _, err := os.Stat(logDir); err != nil && os.IsNotExist(err) { + if err = os.MkdirAll(logDir, 0750); err != nil { + return "", errors.Wrap(err, "error when create kbcli log directory") + } + } + return logDir, nil +} + // GetKubeconfigDir returns the kubeconfig directory. func GetKubeconfigDir() string { var kubeconfigDir string