Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
cluster manager from the `bin` directory.
- `tt tcm status`: added command to check TCM runtime status (modes: `watchdog` or `interactive`).
- `tt tcm stop`: add command for graceful termination of TCM processes (modes: `watchdog` or `interactive`).
- Add support manage installed `tcm` versions via `tt binaries` CLI.
- Added support for completion with shell `fish` see
the command `tt completion fish`.

Expand Down
1 change: 1 addition & 0 deletions cli/binary/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func ListBinaries(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) (err error
search.ProgramCe,
search.ProgramDev,
search.ProgramEe,
search.ProgramTcm,
}
fmt.Println("List of installed binaries:")
for _, program := range programs {
Expand Down
94 changes: 44 additions & 50 deletions cli/binary/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,72 +93,66 @@ func ChooseVersion(binDir string, program search.Program) (string, error) {
return version, err
}

// switchTt switches 'tt' program.
func switchTt(switchCtx SwitchCtx) error {
log.Infof("Switching to %s %s.", switchCtx.Program, switchCtx.Version)
// switchHeaders makes symlink for required version of headers.
func switchHeaders(switchCtx *SwitchCtx, versionStr string) error {
includeDir := filepath.Join(switchCtx.IncDir, "include")

ttVersion := switchCtx.Version
if !strings.HasPrefix(switchCtx.Version, "v") {
ttVersion = "v" + ttVersion
if !util.IsDir(filepath.Join(includeDir, versionStr)) {
return fmt.Errorf("headers %s is not installed in current environment", versionStr)
}
versionStr := search.ProgramTt.String() + version.FsSeparator + ttVersion

if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) {
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir, "tt"), true)
if err != nil {
return fmt.Errorf("failed to switch version: %s", err)
}
log.Infof("Done")
} else {
return fmt.Errorf("%s %s is not installed in current environment",
switchCtx.Program, switchCtx.Version)
err := util.CreateSymlink(versionStr,
filepath.Join(includeDir, switchCtx.Program.Exec()),
true)
if err != nil {
return fmt.Errorf("failed create symlink: %s", err)
}
return nil
}

// switchTarantool switches 'tarantool' program.
func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
log.Infof("Switching to %s %s.", switchCtx.Program, switchCtx.Version)
var versionStr string
if enterprise {
versionStr = search.ProgramEe.String() + version.FsSeparator + switchCtx.Version
} else {
versionStr = search.ProgramCe.String() + version.FsSeparator + switchCtx.Version
// switchBinary makes symlink for required binary version.
func switchBinary(switchCtx *SwitchCtx, versionStr string) error {
newBinary := filepath.Join(switchCtx.BinDir, versionStr)
if !util.IsRegularFile(newBinary) {
return fmt.Errorf("binary %s is not installed in current environment", newBinary)
}
if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) &&
util.IsDir(filepath.Join(switchCtx.IncDir, "include", versionStr)) {
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir,
"tarantool"), true)
if err != nil {
return fmt.Errorf("failed to switch version: %s", err)
}
err = util.CreateSymlink(versionStr, filepath.Join(switchCtx.IncDir,
"include", "tarantool"), true)
if err != nil {
return fmt.Errorf("failed to switch version: %s", err)
}
log.Infof("Done")
} else {
return fmt.Errorf("%s %s is not installed in current environment",
switchCtx.Program, switchCtx.Version)

err := util.CreateSymlink(versionStr,
filepath.Join(switchCtx.BinDir, switchCtx.Program.Exec()),
true)
if err != nil {
return fmt.Errorf("failed create symlink: %s", err)
}
return nil
}

// Switch switches binaries.
func Switch(switchCtx SwitchCtx) error {
var err error

func Switch(switchCtx *SwitchCtx) error {
switch switchCtx.Program {
case search.ProgramTt:
err = switchTt(switchCtx)
case search.ProgramCe:
err = switchTarantool(switchCtx, false)
case search.ProgramEe:
err = switchTarantool(switchCtx, true)
default:
if !strings.HasPrefix(switchCtx.Version, "v") {
switchCtx.Version = "v" + switchCtx.Version
}

case search.ProgramUnknown:
return fmt.Errorf("unknown application: %s", switchCtx.Program)
}

return err
versionStr := switchCtx.Program.String() + version.FsSeparator + switchCtx.Version
log.Infof("Switching to %s", versionStr)

err := switchBinary(switchCtx, versionStr)
if err != nil {
return fmt.Errorf("failed to switch binary: %s", err)
}

if switchCtx.Program.IsTarantool() {
err = switchHeaders(switchCtx, versionStr)
if err != nil {
return fmt.Errorf("failed to switch headers: %s", err)
}
}

log.Infof("Done")
return nil
}
10 changes: 5 additions & 5 deletions cli/binary/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSwitchTarantool(t *testing.T) {
testCtx.Program, err = search.ParseProgram("tarantool")
assert.NoError(t, err)
testCtx.Version = "2.10.3"
err = Switch(testCtx)
err = Switch(&testCtx)
assert.Nil(t, err)
assert.FileExists(t, filepath.Join(testCtx.BinDir, "tarantool"))
assert.FileExists(t, filepath.Join(testCtx.IncDir, "include/tarantool"))
Expand All @@ -54,8 +54,8 @@ func TestSwitchUnknownProgram(t *testing.T) {
testCtx.Program, err = search.ParseProgram("tarantool-foo")
assert.Error(t, err)
testCtx.Version = "2.10.3"
err = Switch(testCtx)
assert.Equal(t, err.Error(), "unknown application: unknown(0)")
err = Switch(&testCtx)
assert.Contains(t, err.Error(), "unknown application: unknown(0)")
}

func TestSwitchNotInstalledVersion(t *testing.T) {
Expand All @@ -66,6 +66,6 @@ func TestSwitchNotInstalledVersion(t *testing.T) {
testCtx.Program, err = search.ParseProgram("tarantool")
assert.NoError(t, err)
testCtx.Version = "2.10.3"
err = Switch(testCtx)
assert.Equal(t, err.Error(), "tarantool 2.10.3 is not installed in current environment")
err = Switch(&testCtx)
assert.Contains(t, err.Error(), "tarantool_2.10.3 is not installed in current environment")
}
11 changes: 7 additions & 4 deletions cli/cmd/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ var binariesSupportedPrograms = []string{
search.ProgramCe.String(),
search.ProgramEe.String(),
search.ProgramTt.String(),
search.ProgramTcm.String(),
}

// NewBinariesCmd creates binaries command.
func NewBinariesCmd() *cobra.Command {
binariesCmd := &cobra.Command{
Use: "binaries",
Use: "binaries",
Short: "Manage installed binaries",
}

switchCmd := &cobra.Command{
Expand All @@ -41,8 +43,9 @@ You will need to choose version using arrow keys in your console.
# Switch with program and version.

$ tt binaries switch tarantool 2.10.4`,
Run: RunModuleFunc(internalSwitchModule),
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
Run: RunModuleFunc(internalSwitchModule),
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
ValidArgs: binariesSupportedPrograms,
}
listCmd := &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -95,7 +98,7 @@ func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
switchCtx.BinDir = cliOpts.Env.BinDir
switchCtx.IncDir = cliOpts.Env.IncludeDir

err = binary.Switch(switchCtx)
err = binary.Switch(&switchCtx)
return err
}

Expand Down
Loading
Loading