Skip to content

Commit

Permalink
chore: add logs dir to store kbcli log (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
1aal authored Nov 14, 2023
2 parents 068e85a + 42f0e34 commit ab2f4e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/action/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ import (

func TestCreate(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Create Suite")
RunSpecs(t, "Action Suite")
}
1 change: 0 additions & 1 deletion pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package cmd

import (
"fmt"

"os"
"strings"

Expand Down
3 changes: 3 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab2f4e5

Please sign in to comment.