feat: switch config file to XDG conform location

The config file is now located in an folder according to the XDG
specification (`XDG_CONFIG_HOME`).

Migration is performed automatically.

This fixes #235.

Signed-off-by: Patrick Pichler <git@patrickpichler.dev>
This commit is contained in:
Patrick Pichler
2023-04-10 18:22:54 +02:00
committed by Patrick Pichler
parent 51b1b352ac
commit dee435514d
5 changed files with 98 additions and 17 deletions

View File

@@ -3,8 +3,10 @@ package util
import (
"context"
"encoding/base64"
"errors"
"fmt"
"math/rand"
"os"
"regexp"
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
@@ -150,3 +152,23 @@ func GetPodListByLabels(client k.Interface,
return pods, nil
}
func FileExists(path string) (bool, error) {
if _, err := os.Stat(path); err == nil {
return true, nil
} else if errors.Is(err, os.ErrNotExist) {
return false, nil
} else {
return false, err
}
}
func EnsureDirExists(dir string) error {
err := os.Mkdir(dir, 0755)
if errors.Is(err, os.ErrExist) {
return nil
}
return err
}