Skip to content

refactor uninstall #1089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 2 additions & 13 deletions cli/cmd/aeon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
aeoncmd "github.com/tarantool/tt/cli/aeon/cmd"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/console"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/running"
"github.com/tarantool/tt/cli/util"
"github.com/tarantool/tt/lib/cluster"
Expand All @@ -37,18 +36,8 @@ func newAeonConnectCmd() *cobra.Command {
tt aeon connect http://localhost:50051
tt aeon connect unix://<socket-path>
tt aeon connect /path/to/config INSTANCE_NAME>`,
PreRunE: func(cmd *cobra.Command, args []string) error {
err := aeonConnectValidateArgs(cmd, args)
util.HandleCmdErr(cmd, err)
return err
},
Run: func(cmd *cobra.Command, args []string) {
cmdCtx.CommandName = cmd.Name()
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalAeonConnect, args)
util.HandleCmdErr(cmd, err)
},
Args: cobra.RangeArgs(1, 2),
Run: TtModuleCmdRun(internalAeonConnect),
Args: cobra.MatchAll(cobra.RangeArgs(1, 2), aeonConnectValidateArgs),
}

aeonCmd.Flags().StringVar(&connectCtx.Ssl.KeyFile, "sslkeyfile", "",
Expand Down
63 changes: 29 additions & 34 deletions cli/cmd/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import (
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/binary"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/search"
"github.com/tarantool/tt/cli/util"
"golang.org/x/exp/slices"
)

var binariesSupportedPrograms = []string{
search.ProgramCe,
search.ProgramEe,
search.ProgramTt,
}

// NewBinariesCmd creates binaries command.
func NewBinariesCmd() *cobra.Command {
var binariesCmd = &cobra.Command{
Expand All @@ -37,64 +41,55 @@ 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: func(cmd *cobra.Command, args []string) {
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalSwitchModule, args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalSwitchModule),
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
}
var listCmd = &cobra.Command{
Use: "list",
Short: "Show a list of installed binaries and their versions.",
Run: func(cmd *cobra.Command, args []string) {
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalListModule, args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalListModule),
}
binariesCmd.AddCommand(switchCmd)
binariesCmd.AddCommand(listCmd)
return binariesCmd
}

// binariesSwitchValidateArgs validates non-flag arguments of 'binaries switch' command.
func binariesSwitchValidateArgs(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
if !slices.Contains(binariesSupportedPrograms, args[0]) {
return fmt.Errorf("not supported program: %s", args[0])
}
}
return nil
}

// internalSwitchModule is a switch module.
func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
if !isConfigExist(cmdCtx) {
return errNoConfig
}
var switchCtx binary.SwitchCtx
supportedPrograms := []string{search.ProgramCe, search.ProgramEe, search.ProgramTt}

var err error
switch len(args) {
case 2:
switchCtx.Version = args[1]
switchCtx.ProgramName = args[0]
if !slices.Contains(supportedPrograms, switchCtx.ProgramName) {
return fmt.Errorf("not supported program: %s", switchCtx.ProgramName)
}
case 1:

if len(args) > 0 {
switchCtx.ProgramName = args[0]
if !slices.Contains(supportedPrograms, switchCtx.ProgramName) {
return fmt.Errorf("not supported program: %s", switchCtx.ProgramName)
}
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramName)
if err != nil {
return err
}
case 0:
switchCtx.ProgramName, err = binary.ChooseProgram(supportedPrograms)
} else {
switchCtx.ProgramName, err = binary.ChooseProgram(binariesSupportedPrograms)
if err != nil {
return err
}
}

if len(args) > 1 {
switchCtx.Version = args[1]
} else {
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramName)
if err != nil {
return err
}
default:
return fmt.Errorf("invalid number of arguments")

}

switchCtx.BinDir = cliOpts.Env.BinDir
switchCtx.IncDir = cliOpts.Env.IncludeDir

Expand Down
10 changes: 2 additions & 8 deletions cli/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/build"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/running"
"github.com/tarantool/tt/cli/util"
)

var (
Expand All @@ -19,12 +17,8 @@ func NewBuildCmd() *cobra.Command {
var buildCmd = &cobra.Command{
Use: "build [<PATH> | <APP_NAME>] [flags]",
Short: `Build an application (default ".")`,
Run: func(cmd *cobra.Command, args []string) {
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalBuildModule, args)
util.HandleCmdErr(cmd, err)
},
Args: cobra.MaximumNArgs(1),
Run: TtModuleCmdRun(internalBuildModule),
Args: cobra.MaximumNArgs(1),
ValidArgsFunction: func(
cmd *cobra.Command,
args []string,
Expand Down
19 changes: 8 additions & 11 deletions cli/cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/checkpoint"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/util"
"github.com/tarantool/tt/cli/version"
)
Expand All @@ -34,16 +33,18 @@ func NewCatCmd() *cobra.Command {
var catCmd = &cobra.Command{
Use: "cat <FILE>...",
Short: "Print into stdout the contents of .snap/.xlog FILE(s)",
Run: func(cmd *cobra.Command, args []string) {
cmdCtx.CommandName = cmd.Name()
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalCatModule, args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalCatModule),
Example: "tt cat /path/to/file.snap /path/to/file.xlog /path/to/dir/ " +
"--timestamp 2024-11-13T14:02:36.818700000+00:00\n" +
" tt cat /path/to/file.snap /path/to/file.xlog /path/to/dir/ " +
"--timestamp=1731592956.818",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("it is required to specify at least one .xlog/.snap file " +
"or directory")
}
return nil
},
}

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

// internalCatModule is a default cat module.
func internalCatModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
if len(args) == 0 {
return errors.New("it is required to specify at least one .xlog or .snap file")
}

walFiles, err := util.CollectWALFiles(args)
if err != nil {
return util.InternalError(
Expand Down
9 changes: 1 addition & 8 deletions cli/cmd/cfg_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/cfg"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/util"
)

var (
Expand All @@ -19,12 +17,7 @@ func NewDumpCmd() *cobra.Command {
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Print environment configuration",
Run: func(cmd *cobra.Command, args []string) {
cmdCtx.CommandName = cmd.Name()
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalDumpModule, args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalDumpModule),
}

dumpCmd.Flags().BoolVarP(&rawDump, "raw", "r", false,
Expand Down
9 changes: 1 addition & 8 deletions cli/cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import (
"github.com/apex/log"
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/running"
"github.com/tarantool/tt/cli/util"
)

// NewCheckCmd creates a new check command.
func NewCheckCmd() *cobra.Command {
var checkCmd = &cobra.Command{
Use: "check [<APPLICATION_NAME>]",
Short: "Check an application file for syntax errors",
Run: func(cmd *cobra.Command, args []string) {
cmdCtx.CommandName = cmd.Name()
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo,
internalCheckModule, args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalCheckModule),
}

return checkCmd
Expand Down
9 changes: 2 additions & 7 deletions cli/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/cmd/internal"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/process_utils"
"github.com/tarantool/tt/cli/running"
"github.com/tarantool/tt/cli/util"
Expand All @@ -23,11 +22,7 @@ func NewCleanCmd() *cobra.Command {
var cleanCmd = &cobra.Command{
Use: "clean [INSTANCE_NAME]",
Short: "Clean instance(s) files",
Run: func(cmd *cobra.Command, args []string) {
err := modules.RunCmd(&cmdCtx, cmd.CommandPath(), &modulesInfo, internalCleanModule,
args)
util.HandleCmdErr(cmd, err)
},
Run: TtModuleCmdRun(internalCleanModule),
ValidArgsFunction: func(
cmd *cobra.Command,
args []string,
Expand Down Expand Up @@ -83,7 +78,7 @@ func clean(run *running.InstanceCtx) error {
}

if confirm || forceRemove {
for file, _ := range removeFiles {
for file := range removeFiles {
err = os.Remove(file)
if err != nil {
return err
Expand Down
Loading
Loading