Skip to content

Commit

Permalink
refactor(binary): rename instill to inst (#191)
Browse files Browse the repository at this point in the history
Because

- to keep the binary name short

This commit

- rename `instill` to `inst`
  • Loading branch information
pinglin committed Oct 4, 2023
1 parent 44345b3 commit f39c7c8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
16 changes: 8 additions & 8 deletions internal/config/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
}

Expand All @@ -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")
}

Expand Down
44 changes: 22 additions & 22 deletions internal/config/config_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"),
},
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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" {
Expand Down Expand Up @@ -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",
Expand All @@ -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"),
},
}

Expand Down Expand Up @@ -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)

Expand All @@ -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" {
Expand Down Expand Up @@ -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",
Expand All @@ -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"),
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/from_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/local/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/local/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdutil/auth_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f39c7c8

Please sign in to comment.