Skip to content

Commit 1b87e24

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 1b87e24

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
145145
return nil
146146
}
147147

148+
// switchTcm switches 'tcm' program.
149+
func switchTcm(switchCtx SwitchCtx) error {
150+
log.Infof("Switching to %s %s.", switchCtx.Program, switchCtx.Version)
151+
versionStr := search.ProgramTcm.String() + version.FsSeparator + switchCtx.Version
152+
if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) {
153+
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir,
154+
"tcm"), true)
155+
if err != nil {
156+
return fmt.Errorf("failed to switch version: %s", err)
157+
}
158+
log.Infof("Done")
159+
} else {
160+
return fmt.Errorf("%s %s is not installed in current environment",
161+
switchCtx.Program, switchCtx.Version)
162+
}
163+
return nil
164+
}
165+
148166
// Switch switches binaries.
149167
func Switch(switchCtx SwitchCtx) error {
150168
var err error
@@ -156,6 +174,8 @@ func Switch(switchCtx SwitchCtx) error {
156174
err = switchTarantool(switchCtx, false)
157175
case search.ProgramEe:
158176
err = switchTarantool(switchCtx, true)
177+
case search.ProgramTcm:
178+
err = switchTcm(switchCtx)
159179
default:
160180
return fmt.Errorf("unknown application: %s", switchCtx.Program)
161181
}

cli/cmd/binaries.go

Lines changed: 6 additions & 3 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",

0 commit comments

Comments
 (0)