Skip to content

Commit

Permalink
feat: add interactive flag
Browse files Browse the repository at this point in the history
to run upterm host without the requrement to automatically accect
connections, --interactive=false could be used as flag to skip the
command prompt for actively confirming accepting new connections.

Signed-off-by: Mario Constanti <[email protected]>
  • Loading branch information
bavarianbidi committed Oct 2, 2023
1 parent 09d7f4b commit 1b50c2c
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions cmd/upterm/command/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
flagGitLabUsers []string
flagSourceHutUsers []string
flagReadOnly bool
flagInteractive bool
)

func hostCmd() *cobra.Command {
Expand Down Expand Up @@ -72,6 +73,7 @@ func hostCmd() *cobra.Command {
cmd.PersistentFlags().StringSliceVar(&flagGitHubUsers, "github-user", nil, "this GitHub user public keys are permitted to connect.")
cmd.PersistentFlags().StringSliceVar(&flagGitLabUsers, "gitlab-user", nil, "this GitLab user public keys are permitted to connect.")
cmd.PersistentFlags().StringSliceVar(&flagSourceHutUsers, "srht-user", nil, "this SourceHut user public keys are permitted to connect.")
cmd.PersistentFlags().BoolVarP(&flagInteractive, "interactive", "", true, "directly launch the given command without accepting input from the user.")
cmd.PersistentFlags().BoolVarP(&flagReadOnly, "read-only", "r", false, "host a read-only session. Clients won't be able to interact.")

return cmd
Expand Down Expand Up @@ -224,20 +226,23 @@ func displaySessionCallback(session *api.GetSessionResponse) error {
return err
}

fmt.Printf("\nRun 'upterm session current' to display this screen again\n\n")
if flagInteractive {

if err := keyboard.Open(); err != nil {
return err
}
defer keyboard.Close()
fmt.Printf("\nRun 'upterm session current' to display this screen again\n\n")

fmt.Println("Press <q> or <ctrl-c> to accept connections...")
for {
char, key, err := keyboard.GetKey()
if err != nil {
if err := keyboard.Open(); err != nil {
return err
} else if key == keyboard.KeyCtrlC || char == 'q' {
break
}
defer keyboard.Close()

fmt.Println("Press <q> or <ctrl-c> to accept connections...")
for {
char, key, err := keyboard.GetKey()
if err != nil {
return err
} else if key == keyboard.KeyCtrlC || char == 'q' {
break
}
}
}

Expand Down

0 comments on commit 1b50c2c

Please sign in to comment.