Skip to content

Commit

Permalink
uninstall: don't refer config.CliOpts in 'uninstall' package
Browse files Browse the repository at this point in the history
  • Loading branch information
elhimov committed Jan 18, 2025
1 parent ba73bf3 commit 2c50b24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func uninstallProgramValidArgsFunc(cmd *cobra.Command, args []string, toComplete
if len(args) > 0 {
return []string{}, cobra.ShellCompDirectiveNoFileComp
}
return uninstall.GetList(cliOpts, cmd.Name()),
return uninstall.GetAvailableVersions(cmd.Name(), cliOpts.Env.BinDir),
cobra.ShellCompDirectiveNoFileComp
}

Expand Down
10 changes: 5 additions & 5 deletions cli/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/tarantool/tt/cli/install"

"github.com/apex/log"
"github.com/tarantool/tt/cli/config"
"github.com/tarantool/tt/cli/search"
"github.com/tarantool/tt/cli/util"
"github.com/tarantool/tt/cli/version"
Expand Down Expand Up @@ -198,18 +197,19 @@ func getDefault(program, dir string) (string, error) {
return ver, nil
}

// GetList generates a list of options to uninstall.
func GetList(cliOpts *config.CliOpts, program string) []string {
// GetAvailableVersions returns a list of the program's versions installed into
// the binDir directory.
func GetAvailableVersions(program string, binDir string) []string {
list := []string{}
re := regexp.MustCompile(
"^" + progRegexp + version.FsSeparator + verRegexp + "$",
)

if cliOpts.Env.BinDir == "" {
if binDir == "" {
return nil
}

installedPrograms, err := os.ReadDir(cliOpts.Env.BinDir)
installedPrograms, err := os.ReadDir(binDir)
if err != nil {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions cli/uninstall/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (mock *mockRepository) ValidateAll() error {
return nil
}

func TestGetList(t *testing.T) {
func TestGetAvailableVersions(t *testing.T) {
assert := assert.New(t)
workDir := t.TempDir()

Expand All @@ -52,13 +52,13 @@ func TestGetList(t *testing.T) {

cliOpts, _, err := configure.GetCliOpts(cfgPath, &mockRepository{})
require.NoError(t, err)
result := GetList(cliOpts, "tt")
result := GetAvailableVersions("tt", cliOpts.Env.BinDir)
assert.Equal(result, []string{"1.2.3"})

result = GetList(cliOpts, "tarantool")
result = GetAvailableVersions("tarantool", cliOpts.Env.BinDir)
assert.Equal(result, []string{"1.2.10"})

result = GetList(cliOpts, "tarantool-ee")
result = GetAvailableVersions("tarantool-ee", cliOpts.Env.BinDir)
assert.Equal(result, []string{"master"})
}

Expand Down

0 comments on commit 2c50b24

Please sign in to comment.