Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 544ca5b

Browse files
committedMar 17, 2025·
to be squashed to previous commit
1 parent e604424 commit 544ca5b

File tree

15 files changed

+79
-76
lines changed

15 files changed

+79
-76
lines changed
 

‎cli/cmd/binaries.go

+27-22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import (
1212
"golang.org/x/exp/slices"
1313
)
1414

15+
var binariesSupportedPrograms = []string{
16+
search.ProgramCe,
17+
search.ProgramEe,
18+
search.ProgramTt,
19+
}
20+
1521
// NewBinariesCmd creates binaries command.
1622
func NewBinariesCmd() *cobra.Command {
1723
var binariesCmd = &cobra.Command{
@@ -42,6 +48,7 @@ You will need to choose version using arrow keys in your console.
4248
internalSwitchModule, args)
4349
util.HandleCmdErr(cmd, err)
4450
},
51+
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
4552
}
4653
var listCmd = &cobra.Command{
4754
Use: "list",
@@ -57,44 +64,42 @@ You will need to choose version using arrow keys in your console.
5764
return binariesCmd
5865
}
5966

67+
// binariesSwitchValidateArgs validates non-flag arguments of 'binaries switch' command.
68+
func binariesSwitchValidateArgs(cmd *cobra.Command, args []string) error {
69+
if len(args) > 0 {
70+
if !slices.Contains(binariesSupportedPrograms, args[0]) {
71+
return fmt.Errorf("not supported program: %s", args[0])
72+
}
73+
}
74+
return nil
75+
}
76+
6077
// internalSwitchModule is a switch module.
6178
func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
6279
if !isConfigExist(cmdCtx) {
6380
return errNoConfig
6481
}
6582
var switchCtx binary.SwitchCtx
66-
supportedPrograms := []string{search.ProgramCe, search.ProgramEe, search.ProgramTt}
67-
6883
var err error
69-
switch len(args) {
70-
case 2:
71-
switchCtx.Version = args[1]
72-
switchCtx.ProgramName = args[0]
73-
if !slices.Contains(supportedPrograms, switchCtx.ProgramName) {
74-
return fmt.Errorf("not supported program: %s", switchCtx.ProgramName)
75-
}
76-
case 1:
84+
85+
if len(args) > 0 {
7786
switchCtx.ProgramName = args[0]
78-
if !slices.Contains(supportedPrograms, switchCtx.ProgramName) {
79-
return fmt.Errorf("not supported program: %s", switchCtx.ProgramName)
80-
}
81-
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramName)
82-
if err != nil {
83-
return err
84-
}
85-
case 0:
86-
switchCtx.ProgramName, err = binary.ChooseProgram(supportedPrograms)
87+
} else {
88+
switchCtx.ProgramName, err = binary.ChooseProgram(binariesSupportedPrograms)
8789
if err != nil {
8890
return err
8991
}
92+
}
93+
94+
if len(args) > 1 {
95+
switchCtx.Version = args[1]
96+
} else {
9097
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramName)
9198
if err != nil {
9299
return err
93100
}
94-
default:
95-
return fmt.Errorf("invalid number of arguments")
96-
97101
}
102+
98103
switchCtx.BinDir = cliOpts.Env.BinDir
99104
switchCtx.IncDir = cliOpts.Env.IncludeDir
100105

‎cli/cmd/cat.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ func NewCatCmd() *cobra.Command {
4444
"--timestamp 2024-11-13T14:02:36.818700000+00:00\n" +
4545
" tt cat /path/to/file.snap /path/to/file.xlog /path/to/dir/ " +
4646
"--timestamp=1731592956.818",
47+
Args: func(cmd *cobra.Command, args []string) error {
48+
if len(args) == 0 {
49+
return errors.New("it is required to specify at least one .xlog/.snap file " +
50+
"or directory")
51+
}
52+
return nil
53+
},
4754
}
4855

4956
catCmd.Flags().Uint64Var(&catFlags.To, "to", catFlags.To,
@@ -66,10 +73,6 @@ func NewCatCmd() *cobra.Command {
6673

6774
// internalCatModule is a default cat module.
6875
func internalCatModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
69-
if len(args) == 0 {
70-
return errors.New("it is required to specify at least one .xlog or .snap file")
71-
}
72-
7376
walFiles, err := util.CollectWALFiles(args)
7477
if err != nil {
7578
return util.InternalError(

‎cli/cmd/create.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func internalCreateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
133133

134134
createCtx := create_ctx.CreateCtx{
135135
AppName: appName,
136+
TemplateName: args[0],
136137
ForceMode: forceMode,
137138
SilentMode: nonInteractiveMode,
138139
VarsFromCli: *varsFromCli,
@@ -141,7 +142,7 @@ func internalCreateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
141142
CliOpts: cliOpts,
142143
}
143144

144-
if err := create.FillCtx(cliOpts, &createCtx, args); err != nil {
145+
if err := create.FillCtx(cliOpts, &createCtx); err != nil {
145146
return err
146147
}
147148

‎cli/cmd/download.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cmd
22

33
import (
4+
"errors"
5+
46
"github.com/spf13/cobra"
57
"github.com/tarantool/tt/cli/cmdcontext"
68
"github.com/tarantool/tt/cli/download"
@@ -28,6 +30,14 @@ func NewDownloadCmd() *cobra.Command {
2830
internalDownloadModule, args)
2931
util.HandleCmdErr(cmd, err)
3032
},
33+
Args: func(cmd *cobra.Command, args []string) error {
34+
if len(args) == 0 {
35+
return errors.New("to download Tarantool SDK, you need to specify the version")
36+
} else if len(args) > 1 {
37+
return errors.New("invalid number of parameters")
38+
}
39+
return nil
40+
},
3141
}
3242

3343
cmd.Flags().BoolVar(&downloadCtx.DevBuild, "dev", false, "download development build")
@@ -39,10 +49,6 @@ func NewDownloadCmd() *cobra.Command {
3949
}
4050

4151
func internalDownloadModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
42-
var err error
43-
if err = download.FillCtx(cmdCtx, &downloadCtx, args); err != nil {
44-
return err
45-
}
46-
52+
downloadCtx.Version = args[0]
4753
return download.DownloadSDK(cmdCtx, downloadCtx, cliOpts)
4854
}

‎cli/cmd/enable.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/spf13/cobra"
@@ -26,17 +27,19 @@ func NewEnableCmd() *cobra.Command {
2627
internalEnableModule, args)
2728
util.HandleCmdErr(cmd, err)
2829
},
30+
Args: func(cmd *cobra.Command, args []string) error {
31+
if len(args) != 1 {
32+
return errors.New("provide the path to a script or application directory")
33+
}
34+
return nil
35+
},
2936
}
3037

3138
return initCmd
3239
}
3340

3441
// internalEnableModule is a default enable module.
3542
func internalEnableModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
36-
if len(args) != 1 {
37-
return fmt.Errorf("provide the path to a script or application directory")
38-
}
39-
4043
if cliOpts.Env.InstancesEnabled == "." {
4144
return fmt.Errorf("enabling application for instances enabled '.' is not supported")
4245
}

‎cli/cmd/install.go

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func newInstallTtCmd() *cobra.Command {
2222
internalInstallModule, args)
2323
util.HandleCmdErr(cmd, err)
2424
},
25+
Args: cobra.MaximumNArgs(1),
2526
}
2627

2728
return tntCmd
@@ -39,6 +40,7 @@ func newInstallTarantoolCmd() *cobra.Command {
3940
internalInstallModule, args)
4041
util.HandleCmdErr(cmd, err)
4142
},
43+
Args: cobra.MaximumNArgs(1),
4244
}
4345

4446
tntCmd.Flags().BoolVarP(&installCtx.BuildInDocker, "use-docker", "", false,
@@ -61,6 +63,7 @@ func newInstallTarantoolEeCmd() *cobra.Command {
6163
internalInstallModule, args)
6264
util.HandleCmdErr(cmd, err)
6365
},
66+
Args: cobra.MaximumNArgs(1),
6467
}
6568

6669
tntCmd.Flags().BoolVar(&installCtx.DevBuild, "dev", false, "install development build")
@@ -86,6 +89,7 @@ func newInstallTarantoolDevCmd() *cobra.Command {
8689
internalInstallModule, args)
8790
util.HandleCmdErr(cmd, err)
8891
},
92+
Args: cobra.ExactArgs(1),
8993
}
9094

9195
tntCmd.Flags().StringVar(&installCtx.IncDir, "include-dir", "",

‎cli/cmd/play.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func NewPlayCmd() *cobra.Command {
6161
"/path/to/dir/ --timestamp 2024-11-13T14:02:36.818700000+00:00\n" +
6262
" tt play app:instance001 /path/to/file.snap /path/to/file.xlog " +
6363
"/path/to/dir/ --timestamp=1731592956.818",
64+
Args: playValidateArgs,
6465
}
6566

6667
playCmd.Flags().StringVarP(&playUsername, "username", "u", "", "username")
@@ -89,13 +90,17 @@ func NewPlayCmd() *cobra.Command {
8990
return playCmd
9091
}
9192

92-
// internalPlayModule is a default play module.
93-
func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
93+
// playValidateArgs validates non-flag arguments 'play' command.
94+
func playValidateArgs(cmd *cobra.Command, args []string) error {
9495
if len(args) < 2 {
9596
return errors.New("it is required to specify an URI and at least one .xlog/.snap file " +
9697
"or directory")
9798
}
99+
return nil
100+
}
98101

102+
// internalPlayModule is a default play module.
103+
func internalPlayModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
99104
// FillCtx returns error if no instances found.
100105
var runningCtx running.RunningCtx
101106
err := running.FillCtx(cliOpts, cmdCtx, &runningCtx, []string{args[0]}, running.ConfigLoadAll)

‎cli/cmd/search.go

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func newSearchTtCmd() *cobra.Command {
2727
internalSearchModule, args)
2828
util.HandleCmdErr(cmd, err)
2929
},
30+
Args: cobra.ExactArgs(0),
3031
}
3132

3233
return tntCmd
@@ -43,6 +44,7 @@ func newSearchTarantoolCmd() *cobra.Command {
4344
internalSearchModule, args)
4445
util.HandleCmdErr(cmd, err)
4546
},
47+
Args: cobra.ExactArgs(0),
4648
}
4749

4850
return tntCmd
@@ -59,6 +61,7 @@ func newSearchTarantoolEeCmd() *cobra.Command {
5961
internalSearchModule, args)
6062
util.HandleCmdErr(cmd, err)
6163
},
64+
Args: cobra.ExactArgs(0),
6265
}
6366
tntCmd.Flags().BoolVar(&debug, "debug", debug,
6467
"search for debug builds of tarantool-ee SDK")

‎cli/cmd/uninstall.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
75
"github.com/tarantool/tt/cli/cmdcontext"
86
"github.com/tarantool/tt/cli/modules"
@@ -26,6 +24,7 @@ func newUninstallTtCmd() *cobra.Command {
2624
InternalUninstallModule, args)
2725
util.HandleCmdErr(cmd, err)
2826
},
27+
Args: cobra.MaximumNArgs(1),
2928
ValidArgsFunction: func(
3029
cmd *cobra.Command,
3130
args []string,
@@ -53,6 +52,7 @@ func newUninstallTarantoolCmd() *cobra.Command {
5352
InternalUninstallModule, args)
5453
util.HandleCmdErr(cmd, err)
5554
},
55+
Args: cobra.MaximumNArgs(1),
5656
ValidArgsFunction: func(
5757
cmd *cobra.Command,
5858
args []string,
@@ -80,6 +80,7 @@ func newUninstallTarantoolEeCmd() *cobra.Command {
8080
InternalUninstallModule, args)
8181
util.HandleCmdErr(cmd, err)
8282
},
83+
Args: cobra.MaximumNArgs(1),
8384
ValidArgsFunction: func(
8485
cmd *cobra.Command,
8586
args []string,
@@ -107,6 +108,7 @@ func newUninstallTarantoolDevCmd() *cobra.Command {
107108
InternalUninstallModule, args)
108109
util.HandleCmdErr(cmd, err)
109110
},
111+
Args: cobra.ExactArgs(0),
110112
}
111113

112114
return tntCmd
@@ -142,8 +144,6 @@ func InternalUninstallModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
142144
programVersion := ""
143145
if len(args) == 1 {
144146
programVersion = args[0]
145-
} else if len(args) > 1 {
146-
return fmt.Errorf("wrong number of arguments")
147147
}
148148

149149
err := uninstall.UninstallProgram(programName, programVersion, cliOpts.Env.BinDir,

‎cli/create/create.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,11 @@ import (
1414
)
1515

1616
// FillCtx fills create context.
17-
func FillCtx(cliOpts *config.CliOpts, createCtx *create_ctx.CreateCtx, args []string) error {
17+
func FillCtx(cliOpts *config.CliOpts, createCtx *create_ctx.CreateCtx) error {
1818
for _, p := range cliOpts.Templates {
1919
createCtx.TemplateSearchPaths = append(createCtx.TemplateSearchPaths, p.Path)
2020
}
2121

22-
if len(args) >= 1 {
23-
createCtx.TemplateName = args[0]
24-
} else {
25-
return fmt.Errorf("missing template name argument. " +
26-
"Try `tt create --help` for more information")
27-
}
28-
2922
workingDir, err := os.Getwd()
3023
if err != nil {
3124
return err

‎cli/download/download.go

+2-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
type DownloadCtx struct {
1818
// SDK version to download.
19-
version string
19+
Version string
2020
// Path where the sdk will be saved.
2121
DirectoryPrefix string
2222
// Download development build.
@@ -41,7 +41,7 @@ func DownloadSDK(cmdCtx *cmdcontext.CmdCtx, downloadCtx DownloadCtx,
4141

4242
log.Info("Search for the requested version...")
4343
ver, err := search.GetTarantoolBundleInfo(cliOpts, false,
44-
downloadCtx.DevBuild, nil, downloadCtx.version)
44+
downloadCtx.DevBuild, nil, downloadCtx.Version)
4545
if err != nil {
4646
return fmt.Errorf("cannot get SDK bundle info: %s", err)
4747
}
@@ -77,15 +77,3 @@ func DownloadSDK(cmdCtx *cmdcontext.CmdCtx, downloadCtx DownloadCtx,
7777

7878
return err
7979
}
80-
81-
func FillCtx(cmdCtx *cmdcontext.CmdCtx, downloadCtx *DownloadCtx, args []string) error {
82-
if len(args) == 0 {
83-
return fmt.Errorf("to download Tarantool SDK, you need to specify the version")
84-
} else if len(args) == 1 {
85-
downloadCtx.version = args[0]
86-
} else if len(args) > 1 {
87-
return fmt.Errorf("invalid number of parameters")
88-
}
89-
90-
return nil
91-
}

‎cli/install/install.go

-5
Original file line numberDiff line numberDiff line change
@@ -1595,17 +1595,12 @@ func FillCtx(cmdCtx *cmdcontext.CmdCtx, installCtx *InstallCtx, args []string) e
15951595
installCtx.skipMasterUpdate = cmdCtx.Cli.NoPrompt
15961596

15971597
if cmdCtx.CommandName == search.ProgramDev {
1598-
if len(args) != 1 {
1599-
return fmt.Errorf("exactly one build directory must be specified")
1600-
}
16011598
installCtx.buildDir = args[0]
16021599
return nil
16031600
}
16041601

16051602
if len(args) == 1 {
16061603
installCtx.version = args[0]
1607-
} else if len(args) > 1 {
1608-
return fmt.Errorf("invalid number of parameters")
16091604
}
16101605

16111606
return nil

‎cli/util/util.go

-4
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,6 @@ func StringToTimestamp(input string) (string, error) {
10011001

10021002
// CollectWALFiles globs files from args.
10031003
func CollectWALFiles(paths []string) ([]string, error) {
1004-
if len(paths) < 1 {
1005-
return nil, errors.New("it is required to specify at least one .xlog/.snap file " +
1006-
"or directory")
1007-
}
10081004
collectedFiles := make([]string, 0)
10091005

10101006
sortSnapFilesFirst := func(left, right string) int {

‎cli/util/util_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,9 @@ func TestCollectWALFiles(t *testing.T) {
816816
expectedErrMsg string
817817
}{
818818
{
819-
name: "no_file",
820-
expectedErrMsg: "it is required to specify at least one .xlog/.snap file or directory",
819+
name: "no_file",
820+
input: []string{},
821+
output: []string{},
821822
},
822823
{
823824
name: "incorrect_file",

‎test/integration/cat/test_cat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(
1313
# Testing with unset .xlog or .snap file.
1414
"",
15-
"it is required to specify at least one .xlog or .snap file",
15+
"it is required to specify at least one .xlog/.snap file or directory",
1616
),
1717
(
1818
"path-to-non-existent-file",

0 commit comments

Comments
 (0)
Please sign in to comment.