Skip to content

Commit 6a7d531

Browse files
committed
binaries: add support for manage TCM
Add support to manage installed `tcm` versions via `tt binaries` CLI. @TarantoolBot Title: add support for manage TCM binaries Add support to manage installed `tcm` versions via `tt binaries` CLI. **Example usage:** List of all installed versions ```sh tt binaries list ``` **Possible output:** ``` List of installed binaries: • tarantool: 2.11.6 3.4.0 [active] • tarantool-ee: gc64-3.4.0-0-r60 [active] gc64-2.11.6-0-r683 • tcm: 1.3.1-0-g074b5ffa 1.2.3-0-geae7e7d49 1.2.0-11-g2d0a0f495 [active] ``` Switch to the specified version ```sh tt binaries switch tcm 1.2.3-0-geae7e7d49 ``` **Possible output:** ``` • Switching to tcm 1.2.3-0-geae7e7d49. • Done ``` Closes #TNTP-2764
1 parent 40507ae commit 6a7d531

File tree

6 files changed

+59
-60
lines changed

6 files changed

+59
-60
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717
manager (TCM) from the customer zone or local `distfiles` directory.
1818
- `tt tcm status`: added command to check TCM runtime status (modes: `watchdog` or `interactive`).
1919
- `tt tcm stop`: add command for graceful termination of TCM processes (modes: `watchdog` or `interactive`).
20+
- Add support manage installed `tcm` versions via `tt binaries` CLI.
2021

2122
### Changed
2223

cli/binary/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func ListBinaries(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) (err error
113113
search.ProgramCe,
114114
search.ProgramDev,
115115
search.ProgramEe,
116+
search.ProgramTcm,
116117
}
117118
fmt.Println("List of installed binaries:")
118119
for _, program := range programs {

cli/binary/switch.go

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -93,72 +93,66 @@ func ChooseVersion(binDir string, program search.Program) (string, error) {
9393
return version, err
9494
}
9595

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

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

106-
if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) {
107-
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir, "tt"), true)
108-
if err != nil {
109-
return fmt.Errorf("failed to switch version: %s", err)
110-
}
111-
log.Infof("Done")
112-
} else {
113-
return fmt.Errorf("%s %s is not installed in current environment",
114-
switchCtx.Program, switchCtx.Version)
104+
err := util.CreateSymlink(versionStr,
105+
filepath.Join(includeDir, switchCtx.Program.Exec()),
106+
true)
107+
if err != nil {
108+
return fmt.Errorf("failed create symlink: %s", err)
115109
}
116110
return nil
117111
}
118112

119-
// switchTarantool switches 'tarantool' program.
120-
func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
121-
log.Infof("Switching to %s %s.", switchCtx.Program, switchCtx.Version)
122-
var versionStr string
123-
if enterprise {
124-
versionStr = search.ProgramEe.String() + version.FsSeparator + switchCtx.Version
125-
} else {
126-
versionStr = search.ProgramCe.String() + version.FsSeparator + switchCtx.Version
113+
// switchBinary makes symlink for required binary version.
114+
func switchBinary(switchCtx *SwitchCtx, versionStr string) error {
115+
newBinary := filepath.Join(switchCtx.BinDir, versionStr)
116+
if !util.IsRegularFile(newBinary) {
117+
return fmt.Errorf("binary %s is not installed in current environment", newBinary)
127118
}
128-
if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) &&
129-
util.IsDir(filepath.Join(switchCtx.IncDir, "include", versionStr)) {
130-
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir,
131-
"tarantool"), true)
132-
if err != nil {
133-
return fmt.Errorf("failed to switch version: %s", err)
134-
}
135-
err = util.CreateSymlink(versionStr, filepath.Join(switchCtx.IncDir,
136-
"include", "tarantool"), true)
137-
if err != nil {
138-
return fmt.Errorf("failed to switch version: %s", err)
139-
}
140-
log.Infof("Done")
141-
} else {
142-
return fmt.Errorf("%s %s is not installed in current environment",
143-
switchCtx.Program, switchCtx.Version)
119+
120+
err := util.CreateSymlink(versionStr,
121+
filepath.Join(switchCtx.BinDir, switchCtx.Program.Exec()),
122+
true)
123+
if err != nil {
124+
return fmt.Errorf("failed create symlink: %s", err)
144125
}
145126
return nil
146127
}
147128

148129
// Switch switches binaries.
149-
func Switch(switchCtx SwitchCtx) error {
150-
var err error
151-
130+
func Switch(switchCtx *SwitchCtx) error {
152131
switch switchCtx.Program {
153132
case search.ProgramTt:
154-
err = switchTt(switchCtx)
155-
case search.ProgramCe:
156-
err = switchTarantool(switchCtx, false)
157-
case search.ProgramEe:
158-
err = switchTarantool(switchCtx, true)
159-
default:
133+
if !strings.HasPrefix(switchCtx.Version, "v") {
134+
switchCtx.Version = "v" + switchCtx.Version
135+
}
136+
137+
case search.ProgramUnknown:
160138
return fmt.Errorf("unknown application: %s", switchCtx.Program)
161139
}
162140

163-
return err
141+
versionStr := switchCtx.Program.String() + version.FsSeparator + switchCtx.Version
142+
log.Infof("Switching to %s", versionStr)
143+
144+
err := switchBinary(switchCtx, versionStr)
145+
if err != nil {
146+
return fmt.Errorf("failed to switch binary: %s", err)
147+
}
148+
149+
if switchCtx.Program.IsTarantool() {
150+
err = switchHeaders(switchCtx, versionStr)
151+
if err != nil {
152+
return fmt.Errorf("failed to switch headers: %s", err)
153+
}
154+
}
155+
156+
log.Infof("Done")
157+
return nil
164158
}

cli/binary/switch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestSwitchUnknownProgram(t *testing.T) {
5555
assert.Error(t, err)
5656
testCtx.Version = "2.10.3"
5757
err = Switch(testCtx)
58-
assert.Equal(t, err.Error(), "unknown application: unknown(0)")
58+
assert.Contains(t, err.Error(), "unknown application: unknown(0)")
5959
}
6060

6161
func TestSwitchNotInstalledVersion(t *testing.T) {
@@ -67,5 +67,5 @@ func TestSwitchNotInstalledVersion(t *testing.T) {
6767
assert.NoError(t, err)
6868
testCtx.Version = "2.10.3"
6969
err = Switch(testCtx)
70-
assert.Equal(t, err.Error(), "tarantool 2.10.3 is not installed in current environment")
70+
assert.Contains(t, err.Error(), "tarantool_2.10.3 is not installed in current environment")
7171
}

cli/cmd/binaries.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ var binariesSupportedPrograms = []string{
1414
search.ProgramCe.String(),
1515
search.ProgramEe.String(),
1616
search.ProgramTt.String(),
17+
search.ProgramTcm.String(),
1718
}
1819

1920
// NewBinariesCmd creates binaries command.
2021
func NewBinariesCmd() *cobra.Command {
2122
binariesCmd := &cobra.Command{
22-
Use: "binaries",
23+
Use: "binaries",
24+
Short: "Manage installed binaries",
2325
}
2426

2527
switchCmd := &cobra.Command{
@@ -41,8 +43,9 @@ You will need to choose version using arrow keys in your console.
4143
# Switch with program and version.
4244
4345
$ tt binaries switch tarantool 2.10.4`,
44-
Run: RunModuleFunc(internalSwitchModule),
45-
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
46+
Run: RunModuleFunc(internalSwitchModule),
47+
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
48+
ValidArgs: binariesSupportedPrograms,
4649
}
4750
listCmd := &cobra.Command{
4851
Use: "list",
@@ -95,7 +98,7 @@ func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
9598
switchCtx.BinDir = cliOpts.Env.BinDir
9699
switchCtx.IncDir = cliOpts.Env.IncludeDir
97100

98-
err = binary.Switch(switchCtx)
101+
err = binary.Switch(&switchCtx)
99102
return err
100103
}
101104

test/integration/binaries/test_switch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_switch(tt_cmd, tmp_path):
3232
)
3333
install_process_rc = install_process.wait()
3434
output = install_process.stdout.read()
35-
assert "Switching to tarantool 2.10.3" in output
35+
assert "Switching to tarantool_2.10.3" in output
3636
assert install_process_rc == 0
3737

3838
bin_path = os.path.join(tt_dir, "bin")
@@ -70,7 +70,7 @@ def test_switch_with_link(tt_cmd, tmp_path):
7070
)
7171
install_process_rc = install_process.wait()
7272
output = install_process.stdout.read()
73-
assert "Switching to tarantool 2.10.3" in output
73+
assert "Switching to tarantool_2.10.3" in output
7474
assert install_process_rc == 0
7575

7676
bin_path = os.path.join(tt_dir, "bin")
@@ -136,7 +136,7 @@ def test_switch_tt(tt_cmd, tmp_path):
136136
)
137137
switch_process_rc = switch_process.wait()
138138
output = switch_process.stdout.read()
139-
assert "Switching to tt 7.7.7" in output
139+
assert "Switching to tt_v7.7.7" in output
140140
assert switch_process_rc == 0
141141

142142
expected_bin = os.path.join(bin_dir_path, "tt_v7.7.7")
@@ -168,7 +168,7 @@ def test_switch_tt_full_version_name(tt_cmd, tmp_path):
168168
)
169169
switch_process_rc = switch_process.wait()
170170
output = switch_process.stdout.read()
171-
assert "Switching to tt v7.7.7" in output
171+
assert "Switching to tt_v7.7.7" in output
172172
assert switch_process_rc == 0
173173

174174
expected_bin = os.path.join(bin_dir_path, "tt_v7.7.7")

0 commit comments

Comments
 (0)