Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add logs dir to store kbcli log #37

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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