| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "io" |
| 6 | "path/filepath" |
| 7 | |
| 8 | "al.essio.dev/pkg/shellescape" |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | |
| 13 | func RunEnvironmentCommand(ctx context.Context, configPath string, args []string, stdin io.Reader, stdout, stderr io.Writer, interactive bool) error { |
| 14 | s := &Server{profile: filepath.Dir(configPath), configPath: configPath} |
| 15 | command := "cd -- " + shellescape.Quote(guestPath(s.environmentDir())) + " && exec " + shellescape.QuoteCommand(args) |
| 16 | terminal := "-T" |
| 17 | if interactive { |
| 18 | terminal = "-tt" |
| 19 | } |
| 20 | cmd := s.sshCommand(ctx, terminal, s.sshTarget(), "--", "exec /bin/bash -lc "+shellescape.Quote(command)) |
| 21 | cmd.Stdin, cmd.Stdout, cmd.Stderr = stdin, stdout, stderr |
| 22 | return cmd.Run() |
| 23 | } |