Skip to content
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

Fix exec breaking with wish #125

Draft
wants to merge 6 commits into
base: main
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
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func bindFlags(cmd *cobra.Command, nameToArg map[string]arg) {
func mainEntrypoint(cmd *cobra.Command, _ []string) {
dev.Debug("~STARTING UP~")
rootOpts := getRootOpts(cmd)
initialModel, options := setup(cmd, rootOpts, "")
initialModel, options := setup(cmd, rootOpts, "", nil)
program := tea.NewProgram(initialModel, options...)

if _, err := program.Run(); err != nil {
Expand Down
18 changes: 13 additions & 5 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
"github.com/charmbracelet/wish/activeterm"
bm "github.com/charmbracelet/wish/bubbletea"
"github.com/spf13/cobra"
"log"
"net"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -58,17 +59,22 @@ var (
)

func serveEntrypoint(cmd *cobra.Command, args []string) {
var err error
host := cmd.Flags().Lookup("host").Value.String()
portStr := cmd.Flags().Lookup("port").Value.String()
port, err := strconv.Atoi(portStr)
if err != nil {
fmt.Println(fmt.Errorf("could not convert %s to integer", portStr))
os.Exit(1)
}
hostKeyPath := cmd.Flags().Lookup("host-key-path").Value.String()
hostKeyPEM := cmd.Flags().Lookup("host-key-pem").Value.String()

options := []ssh.Option{wish.WithAddress(fmt.Sprintf("%s:%d", host, port))}
options := []ssh.Option{wish.WithAddress(net.JoinHostPort(host, portStr))}

// Allocate a pty.
// This creates a pseudoconsole on windows, compatibility is limited in that case
options = append(options, ssh.AllocatePty())

if hostKeyPath != "" {
options = append(options, wish.WithHostKeyPath(hostKeyPath))
}
Expand All @@ -77,6 +83,8 @@ func serveEntrypoint(cmd *cobra.Command, args []string) {
}
middleware := wish.WithMiddleware(
bm.Middleware(generateTeaHandler(cmd)),
// ensure the user has requested a tty
activeterm.Middleware(),
customLoggingMiddleware(),
)
options = append(options, middleware)
Expand All @@ -88,7 +96,7 @@ func serveEntrypoint(cmd *cobra.Command, args []string) {

done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
log.Printf("Starting SSH server on %s:%d", host, port)
log.Printf("Starting SSH server on %s:%s", host, portStr)
go func() {
if err = s.ListenAndServe(); err != nil {
log.Fatalln(err)
Expand All @@ -112,6 +120,6 @@ func generateTeaHandler(cmd *cobra.Command) func(ssh.Session) (tea.Model, []tea.
if sshCommands := s.Command(); len(sshCommands) == 1 {
overrideToken = strings.TrimSpace(sshCommands[0])
}
return setup(cmd, changedOpts, overrideToken)
return setup(cmd, changedOpts, overrideToken, s)
}
}
4 changes: 2 additions & 2 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func getRootOpts(cmd *cobra.Command) []string {
return opts
}

func setup(cmd *cobra.Command, rootOpts []string, overrideToken string) (app.Model, []tea.ProgramOption) {
initialModel := app.InitialModel(getConfig(cmd, rootOpts, overrideToken))
func setup(cmd *cobra.Command, rootOpts []string, overrideToken string, session ssh.Session) (app.Model, []tea.ProgramOption) {
initialModel := app.InitialModel(getConfig(cmd, rootOpts, overrideToken), session)
return initialModel, []tea.ProgramOption{tea.WithAltScreen()}
}
40 changes: 22 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ require (
github.com/atotto/clipboard v0.1.4
github.com/carlmjohnson/versioninfo v0.22.4
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.7.1
github.com/charmbracelet/ssh v0.0.0-20221117183211-483d43d97103
github.com/charmbracelet/wish v1.1.1
github.com/charmbracelet/bubbletea v0.26.1
github.com/charmbracelet/lipgloss v0.10.0
github.com/charmbracelet/ssh v0.0.0-20240401141849-854cddfa2917
github.com/charmbracelet/wish v1.4.0
github.com/hashicorp/nomad/api v0.0.0-20230619092614-e29ad68c588d
github.com/itchyny/gojq v0.12.13
github.com/moby/term v0.5.0
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/caarlos0/sshmarshal v0.1.0 // indirect
github.com/charmbracelet/keygen v0.4.2 // indirect
github.com/charmbracelet/log v0.2.2 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/charmbracelet/keygen v0.5.0 // indirect
github.com/charmbracelet/log v0.4.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240425164147-ba2a9512b05f // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240425164147-ba2a9512b05f // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/creack/pty v1.1.21 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand All @@ -41,26 +44,27 @@ require (
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
github.com/u-root/u-root v0.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading