diff --git a/internal/config/config_file.go b/internal/config/config_file.go index 755491e..e6ef1c5 100644 --- a/internal/config/config_file.go +++ b/internal/config/config_file.go @@ -31,12 +31,12 @@ func ConfigDir() string { if a := os.Getenv(INSTILL_CONFIG_DIR); a != "" { path = a } else if b := os.Getenv(XDG_CONFIG_HOME); b != "" { - path = filepath.Join(b, "instill") + path = filepath.Join(b, "inst") } else if c := os.Getenv(APP_DATA); runtime.GOOS == "windows" && c != "" { path = filepath.Join(c, "Instill CLI") } else { d, _ := os.UserHomeDir() - path = filepath.Join(d, ".config", "instill") + path = filepath.Join(d, ".config", "inst") } // If the path does not exist and the INSTILL_CONFIG_DIR flag is not set try @@ -55,12 +55,12 @@ func ConfigDir() string { func StateDir() string { var path string if a := os.Getenv(XDG_STATE_HOME); a != "" { - path = filepath.Join(a, "instill") + path = filepath.Join(a, "inst") } else if b := os.Getenv(LOCAL_APP_DATA); runtime.GOOS == "windows" && b != "" { path = filepath.Join(b, "Instill CLI") } else { c, _ := os.UserHomeDir() - path = filepath.Join(c, ".local", "instill", "state") + path = filepath.Join(c, ".local", "inst", "state") } // If the path does not exist try migrating state from default paths @@ -78,12 +78,12 @@ func StateDir() string { func DataDir() string { var path string if a := os.Getenv(XDG_DATA_HOME); a != "" { - path = filepath.Join(a, "instill") + path = filepath.Join(a, "inst") } else if b := os.Getenv(LOCAL_APP_DATA); runtime.GOOS == "windows" && b != "" { path = filepath.Join(b, "Instill CLI") } else { c, _ := os.UserHomeDir() - path = filepath.Join(c, ".local", "share", "instill") + path = filepath.Join(c, ".local", "share", "inst") } return path @@ -96,7 +96,7 @@ var errNotExist = errors.New("not exist") // If configs exist then move them to newPath func autoMigrateConfigDir(newPath string) error { path, err := os.UserHomeDir() - if oldPath := filepath.Join(path, ".config", "instill"); err == nil && dirExists(oldPath) { + if oldPath := filepath.Join(path, ".config", "inst"); err == nil && dirExists(oldPath) { return migrateDir(oldPath, newPath) } @@ -107,7 +107,7 @@ func autoMigrateConfigDir(newPath string) error { // If state file exist then move it to newPath func autoMigrateStateDir(newPath string) error { path, err := os.UserHomeDir() - if oldPath := filepath.Join(path, ".config", "instill"); err == nil && dirExists(oldPath) { + if oldPath := filepath.Join(path, ".config", "inst"); err == nil && dirExists(oldPath) { return migrateFile(oldPath, newPath, "state.yml") } diff --git a/internal/config/config_file_test.go b/internal/config/config_file_test.go index 7e9a80c..d9df6dd 100644 --- a/internal/config/config_file_test.go +++ b/internal/config/config_file_test.go @@ -174,29 +174,29 @@ func Test_ConfigDir(t *testing.T) { "USERPROFILE": tempDir, "HOME": tempDir, }, - output: filepath.Join(tempDir, ".config", "instill"), + output: filepath.Join(tempDir, ".config", "inst"), }, { name: "INSTILL_CONFIG_DIR specified", env: map[string]string{ - "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "instill_config_dir"), + "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "inst_config_dir"), }, - output: filepath.Join(tempDir, "instill_config_dir"), + output: filepath.Join(tempDir, "inst_config_dir"), }, { name: "XDG_CONFIG_HOME specified", env: map[string]string{ "XDG_CONFIG_HOME": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, { name: "INSTILL_CONFIG_DIR and XDG_CONFIG_HOME specified", env: map[string]string{ - "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "instill_config_dir"), + "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "inst_config_dir"), "XDG_CONFIG_HOME": tempDir, }, - output: filepath.Join(tempDir, "instill_config_dir"), + output: filepath.Join(tempDir, "inst_config_dir"), }, { name: "AppData specified", @@ -210,10 +210,10 @@ func Test_ConfigDir(t *testing.T) { name: "INSTILL_CONFIG_DIR and AppData specified", onlyWindows: true, env: map[string]string{ - "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "instill_config_dir"), + "INSTILL_CONFIG_DIR": filepath.Join(tempDir, "inst_config_dir"), "AppData": tempDir, }, - output: filepath.Join(tempDir, "instill_config_dir"), + output: filepath.Join(tempDir, "inst_config_dir"), }, { name: "XDG_CONFIG_HOME and AppData specified", @@ -222,7 +222,7 @@ func Test_ConfigDir(t *testing.T) { "XDG_CONFIG_HOME": tempDir, "AppData": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, } @@ -249,7 +249,7 @@ func Test_ConfigDir(t *testing.T) { } func Test_configFile_Write_toDisk(t *testing.T) { - configDir := filepath.Join(t.TempDir(), ".config", "instill") + configDir := filepath.Join(t.TempDir(), ".config", "inst") _ = os.MkdirAll(configDir, 0755) os.Setenv(INSTILL_CONFIG_DIR, configDir) defer os.Unsetenv(INSTILL_CONFIG_DIR) @@ -296,7 +296,7 @@ func Test_autoMigrateConfigDir_noMigration_notExist(t *testing.T) { func Test_autoMigrateConfigDir_noMigration_samePath(t *testing.T) { homeDir := t.TempDir() - migrateDir := filepath.Join(homeDir, ".config", "instill") + migrateDir := filepath.Join(homeDir, ".config", "inst") err := os.MkdirAll(migrateDir, 0755) assert.NoError(t, err) @@ -319,8 +319,8 @@ func Test_autoMigrateConfigDir_noMigration_samePath(t *testing.T) { func Test_autoMigrateConfigDir_migration(t *testing.T) { homeDir := t.TempDir() migrateDir := t.TempDir() - homeConfigDir := filepath.Join(homeDir, ".config", "instill") - migrateConfigDir := filepath.Join(migrateDir, ".config", "instill") + homeConfigDir := filepath.Join(homeDir, ".config", "inst") + migrateConfigDir := filepath.Join(migrateDir, ".config", "inst") homeEnvVar := "HOME" if runtime.GOOS == "windows" { @@ -366,14 +366,14 @@ func Test_StateDir(t *testing.T) { "USERPROFILE": tempDir, "HOME": tempDir, }, - output: filepath.Join(tempDir, ".local", "instill", "state"), + output: filepath.Join(tempDir, ".local", "inst", "state"), }, { name: "XDG_STATE_HOME specified", env: map[string]string{ "XDG_STATE_HOME": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, { name: "LocalAppData specified", @@ -390,7 +390,7 @@ func Test_StateDir(t *testing.T) { "XDG_STATE_HOME": tempDir, "LocalAppData": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, } @@ -438,7 +438,7 @@ func Test_autoMigrateStateDir_noMigration_notExist(t *testing.T) { func Test_autoMigrateStateDir_noMigration_samePath(t *testing.T) { homeDir := t.TempDir() - migrateDir := filepath.Join(homeDir, ".config", "instill") + migrateDir := filepath.Join(homeDir, ".config", "inst") err := os.MkdirAll(migrateDir, 0755) assert.NoError(t, err) @@ -461,8 +461,8 @@ func Test_autoMigrateStateDir_noMigration_samePath(t *testing.T) { func Test_autoMigrateStateDir_migration(t *testing.T) { homeDir := t.TempDir() migrateDir := t.TempDir() - homeConfigDir := filepath.Join(homeDir, ".config", "instill") - migrateStateDir := filepath.Join(migrateDir, ".local", "instill") + homeConfigDir := filepath.Join(homeDir, ".config", "inst") + migrateStateDir := filepath.Join(migrateDir, ".local", "inst") homeEnvVar := "HOME" if runtime.GOOS == "windows" { @@ -509,14 +509,14 @@ func Test_DataDir(t *testing.T) { "USERPROFILE": tempDir, "HOME": tempDir, }, - output: filepath.Join(tempDir, ".local", "share", "instill"), + output: filepath.Join(tempDir, ".local", "share", "inst"), }, { name: "XDG_DATA_HOME specified", env: map[string]string{ "XDG_DATA_HOME": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, { name: "LocalAppData specified", @@ -533,7 +533,7 @@ func Test_DataDir(t *testing.T) { "XDG_DATA_HOME": tempDir, "LocalAppData": tempDir, }, - output: filepath.Join(tempDir, "instill"), + output: filepath.Join(tempDir, "inst"), }, } diff --git a/internal/config/from_file_test.go b/internal/config/from_file_test.go index 1c9ca69..01de926 100644 --- a/internal/config/from_file_test.go +++ b/internal/config/from_file_test.go @@ -24,7 +24,7 @@ func Test_HostsTyped(t *testing.T) { } func Test_fileConfig_Typed(t *testing.T) { - configDir := filepath.Join(t.TempDir(), ".local", "instill") + configDir := filepath.Join(t.TempDir(), ".local", "inst") _ = os.MkdirAll(configDir, 0755) os.Setenv(INSTILL_CONFIG_DIR, configDir) defer os.Unsetenv(INSTILL_CONFIG_DIR) diff --git a/pkg/cmd/local/deploy.go b/pkg/cmd/local/deploy.go index df6e529..fe6bdd5 100644 --- a/pkg/cmd/local/deploy.go +++ b/pkg/cmd/local/deploy.go @@ -79,7 +79,7 @@ func NewDeployCmd(f *cmdutil.Factory, runF func(*DeployOptions) error) *cobra.Co if err != nil { logger.Error("Couldn't get Home directory", err) } - dir := filepath.Join(d, ".local", "instill") + string(os.PathSeparator) + dir := filepath.Join(d, ".local", "inst") + string(os.PathSeparator) cmd.Flags().StringVarP(&opts.Path, "path", "p", dir, "Destination directory") return cmd diff --git a/pkg/cmd/local/deploy_test.go b/pkg/cmd/local/deploy_test.go index 575f26f..65009eb 100644 --- a/pkg/cmd/local/deploy_test.go +++ b/pkg/cmd/local/deploy_test.go @@ -20,7 +20,7 @@ func TestLocalDeployCmd(t *testing.T) { if err != nil { logger.Error("Couldn't get home directory", err) } - dir := filepath.Join(d, ".local", "instill") + string(os.PathSeparator) + dir := filepath.Join(d, ".local", "inst") + string(os.PathSeparator) tests := []struct { name string stdin string @@ -102,7 +102,7 @@ func TestLocalDeployCmdRun(t *testing.T) { if err != nil { logger.Error("Couldn't get home directory", err) } - dir := filepath.Join(d, ".local", "instill") + string(os.PathSeparator) + dir := filepath.Join(d, ".local", "inst") + string(os.PathSeparator) tests := []struct { name string input *DeployOptions diff --git a/pkg/cmdutil/auth_check_test.go b/pkg/cmdutil/auth_check_test.go index fa8f90b..cddfe17 100644 --- a/pkg/cmdutil/auth_check_test.go +++ b/pkg/cmdutil/auth_check_test.go @@ -11,7 +11,7 @@ import ( ) func Test_CheckAuth(t *testing.T) { - configDir := filepath.Join(t.TempDir(), ".config", "instill") + configDir := filepath.Join(t.TempDir(), ".config", "inst") _ = os.MkdirAll(configDir, 0755) os.Setenv(config.INSTILL_CONFIG_DIR, configDir) defer os.Unsetenv(config.INSTILL_CONFIG_DIR)