diff --git a/pkg/znet/commands.go b/pkg/znet/commands.go index 3e67e8ec..6519a9fe 100644 --- a/pkg/znet/commands.go +++ b/pkg/znet/commands.go @@ -7,7 +7,6 @@ import ( osexec "os/exec" "path/filepath" "runtime" - "sort" "strings" "syscall" "time" @@ -16,7 +15,6 @@ import ( "github.com/pkg/errors" "github.com/CoreumFoundation/coreum-tools/pkg/libexec" - "github.com/CoreumFoundation/coreum-tools/pkg/logger" "github.com/CoreumFoundation/coreum-tools/pkg/must" "github.com/CoreumFoundation/coreum-tools/pkg/parallel" "github.com/CoreumFoundation/coreum/v4/pkg/config/constant" @@ -25,7 +23,6 @@ import ( "github.com/CoreumFoundation/crust/infra/apps/cored" "github.com/CoreumFoundation/crust/infra/targets" "github.com/CoreumFoundation/crust/infra/testing" - "github.com/CoreumFoundation/crust/pkg/znet/tmux" ) var exe = must.String(filepath.EvalSymlinks(must.String(os.Executable()))) @@ -211,43 +208,6 @@ func Spec(spec *infra.Spec) error { return nil } -// Console starts tmux session on top of running environment. -func Console(ctx context.Context, configF *infra.ConfigFactory) error { - spec := infra.NewSpec(configF) - config := NewConfig(configF, spec) - - if err := tmux.Kill(ctx, config.EnvName); err != nil { - return err - } - - containers := map[string]string{} - for appName, app := range spec.Apps { - if app.Info().Status == infra.AppStatusRunning { - containers[appName] = app.Info().Container - } - } - if len(containers) == 0 { - logger.Get(ctx).Info("There are no running applications to show in tmux console") - return nil - } - - appNames := make([]string, 0, len(containers)) - for appName := range containers { - appNames = append(appNames, appName) - } - sort.Strings(appNames) - - for _, appName := range appNames { - if err := tmux.ShowContainerLogs(ctx, config.EnvName, appName, containers[appName]); err != nil { - return err - } - } - if err := tmux.Attach(ctx, config.EnvName); err != nil { - return err - } - return tmux.Kill(ctx, config.EnvName) -} - // CoverageConvert converts & stores coverage from the first cored app we find. func CoverageConvert(ctx context.Context, configF *infra.ConfigFactory) error { spec := infra.NewSpec(configF) diff --git a/pkg/znet/main.go b/pkg/znet/main.go index 814d0ae4..f8cbef6c 100644 --- a/pkg/znet/main.go +++ b/pkg/znet/main.go @@ -32,7 +32,6 @@ func Main() { rootCmd.AddCommand(removeCmd(ctx, configF, cmdF)) rootCmd.AddCommand(testCmd(ctx, configF, cmdF)) rootCmd.AddCommand(specCmd(configF, cmdF)) - rootCmd.AddCommand(consoleCmd(ctx, configF, cmdF)) rootCmd.AddCommand(coverageConvertCmd(ctx, configF, cmdF)) return rootCmd.Execute() @@ -131,16 +130,6 @@ func specCmd(configF *infra.ConfigFactory, cmdF *CmdFactory) *cobra.Command { } } -func consoleCmd(ctx context.Context, configF *infra.ConfigFactory, cmdF *CmdFactory) *cobra.Command { - return &cobra.Command{ - Use: "console", - Short: "Starts tmux console on top of running environment", - RunE: cmdF.Cmd(func() error { - return Console(ctx, configF) - }), - } -} - func coverageConvertCmd(ctx context.Context, configF *infra.ConfigFactory, cmdF *CmdFactory) *cobra.Command { cmd := &cobra.Command{ Use: "coverage-convert", diff --git a/pkg/znet/tmux/tmux.go b/pkg/znet/tmux/tmux.go deleted file mode 100644 index 0894e1bc..00000000 --- a/pkg/znet/tmux/tmux.go +++ /dev/null @@ -1,60 +0,0 @@ -package tmux - -import ( - "context" - "os" - - "github.com/pkg/errors" - - "github.com/CoreumFoundation/coreum-tools/pkg/libexec" - "github.com/CoreumFoundation/crust/exec" -) - -// Attach attaches to tmux session. -func Attach(ctx context.Context, sessionName string) error { - cmd := exec.TMux("attach-session", "-t", sessionName) - cmd.Stdin = os.Stdin - return libexec.Exec(ctx, cmd) -} - -// ShowContainerLogs adds new window to tmux session presenting logs from docker container. -func ShowContainerLogs(ctx context.Context, sessionName, windowName, container string) error { - hasSession, err := sessionExists(ctx, sessionName) - if err != nil { - return err - } - - cmd := []string{"docker", "logs", "-f", container} - if hasSession { - return libexec.Exec( - ctx, - exec.TMux(append([]string{"new-window", "-d", "-n", windowName, "-t", sessionName + ":"}, cmd...)...), - ) - } - return libexec.Exec( - ctx, - exec.TMux(append([]string{"new-session", "-d", "-s", sessionName, "-n", windowName}, cmd...)...), - ) -} - -// Kill kills tmux session. -func Kill(ctx context.Context, sessionName string) error { - hasSession, err := sessionExists(ctx, sessionName) - if err != nil { - return err - } - if !hasSession { - return nil - } - cmd := exec.TMux("kill-session", "-t", sessionName) - cmd.Stdin = os.Stdin - return libexec.Exec(ctx, cmd) -} - -func sessionExists(ctx context.Context, sessionName string) (bool, error) { - err := libexec.Exec(ctx, exec.TMuxNoOut("has-session", "-t", sessionName)) - if err != nil && errors.Is(err, ctx.Err()) { - return false, err - } - return err == nil, nil -}