|
@@ -9,11 +9,17 @@ import (
|
|
"github.com/ente-io/cli/pkg/secrets"
|
|
"github.com/ente-io/cli/pkg/secrets"
|
|
"github.com/ente-io/cli/utils/constants"
|
|
"github.com/ente-io/cli/utils/constants"
|
|
"log"
|
|
"log"
|
|
|
|
+ "os"
|
|
|
|
+ "path/filepath"
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
- cliDBPath := ""
|
|
|
|
|
|
+ cliDBPath, err := GetCLIConfigPath()
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Fatalf("Could not create cli config path\n%v\n", err)
|
|
|
|
+ }
|
|
|
|
+ db, err := pkg.GetDB(fmt.Sprintf("%sente-cli.db", cliDBPath))
|
|
if secrets.IsRunningInContainer() {
|
|
if secrets.IsRunningInContainer() {
|
|
cliDBPath = constants.CliDataPath
|
|
cliDBPath = constants.CliDataPath
|
|
_, err := internal.ValidateDirForWrite(cliDBPath)
|
|
_, err := internal.ValidateDirForWrite(cliDBPath)
|
|
@@ -21,7 +27,7 @@ func main() {
|
|
log.Fatalf("Please mount a volume to %s to persist cli data\n%v\n", cliDBPath, err)
|
|
log.Fatalf("Please mount a volume to %s to persist cli data\n%v\n", cliDBPath, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- db, err := pkg.GetDB(fmt.Sprintf("%sente-cli.db", cliDBPath))
|
|
|
|
|
|
+
|
|
if err != nil {
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), "timeout") {
|
|
if strings.Contains(err.Error(), "timeout") {
|
|
log.Fatalf("Please close all other instances of the cli and try again\n%v\n", err)
|
|
log.Fatalf("Please close all other instances of the cli and try again\n%v\n", err)
|
|
@@ -48,3 +54,28 @@ func main() {
|
|
}()
|
|
}()
|
|
cmd.Execute(&ctrl)
|
|
cmd.Execute(&ctrl)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// GetCLIConfigPath returns the path to the .ente-cli folder and creates it if it doesn't exist.
|
|
|
|
+func GetCLIConfigPath() (string, error) {
|
|
|
|
+ if os.Getenv("ENTE_CLI_CONFIG_PATH") != "" {
|
|
|
|
+ return os.Getenv("ENTE_CLI_CONFIG_PATH"), nil
|
|
|
|
+ }
|
|
|
|
+ // Get the user's home directory
|
|
|
|
+ homeDir, err := os.UserHomeDir()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Create the path for the .ente-cli folder
|
|
|
|
+ cliDBPath := filepath.Join(homeDir, ".ente-cli")
|
|
|
|
+
|
|
|
|
+ // Check if the folder already exists, if not, create it
|
|
|
|
+ if _, err := os.Stat(cliDBPath); os.IsNotExist(err) {
|
|
|
|
+ err := os.MkdirAll(cliDBPath, 0755)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cliDBPath, nil
|
|
|
|
+}
|