diff --git a/cmd/exec.go b/cmd/exec.go index c7c1bb73..4aa7ac4d 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -9,10 +9,11 @@ import ( var ( execCmd = &cobra.Command{ - Use: "exec", - Short: "Exec into a running task", - Long: `Exec into a running nomad task`, - Run: execEntrypoint, + Use: "exec", + Short: "Exec into a running task", + Long: `Exec into a running nomad task`, + Run: execEntrypoint, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return nil }, } ) @@ -25,7 +26,6 @@ func execEntrypoint(cmd *cobra.Command, args []string) { allocID := args[0] task := args[1] execArgs := args[2:] - fmt.Println(fmt.Sprintf("allocID: %s, task: %s", allocID, task)) _, err = nomad.AllocExec(client, allocID, task, execArgs) if err != nil { fmt.Println(fmt.Errorf("could not exec into task: %v", err)) diff --git a/internal/tui/nomad/exec.go b/internal/tui/nomad/exec.go index 44be8403..ce93b3ab 100644 --- a/internal/tui/nomad/exec.go +++ b/internal/tui/nomad/exec.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/hashicorp/nomad/api" "github.com/moby/term" + "github.com/robinovitch61/wander/internal/tui/formatter" "golang.org/x/sys/unix" "io" "os" @@ -13,9 +14,15 @@ import ( "syscall" ) -// TODO: code review this -// TODO: clear screen on start of exec -// TODO: don't print config file used on exec +// TODO: +// - [ ] code review this +// - [x] clear screen on start of exec +// - [ ] don't print config file used on exec +// - [ ] update gif +// - [ ] cmd human friendly (not full 36char id) +// - [ ] warning message that "you're in wander" +// - [ ] try with bash +// - [ ] improve help text on wander exec type ExecCompleteMsg struct { Output string @@ -48,6 +55,10 @@ func AllocExec(client *api.Client, allocID, task string, args []string) (int, er func execImpl(client *api.Client, alloc *api.Allocation, task string, command []string, escapeChar string, stdin io.Reader, stdout, stderr io.WriteCloser) (int, error) { + // attempt to clear screen + os.Stdout.Write([]byte("\033c")) + fmt.Println(fmt.Sprintf("Exec session for %s (%s), task %s", alloc.Name, formatter.ShortAllocID(alloc.ID), task)) + sizeCh := make(chan api.TerminalSize, 1) ctx, cancelFn := context.WithCancel(context.Background())