55package commands
66
77import (
8- "fmt"
9- "os"
10- "os/exec"
11-
128 log "github.com/Sirupsen/logrus"
139
1410 types "github.com/scaleway/scaleway-cli/commands/types"
11+ "github.com/scaleway/scaleway-cli/utils"
1512)
1613
1714var cmdAttach = & types.Command {
@@ -33,8 +30,6 @@ func init() {
3330// Flags
3431var attachHelp bool // -h, --help flag
3532
36- const termjsBin string = "termjs-cli"
37-
3833func runAttach (cmd * types.Command , args []string ) {
3934 if attachHelp {
4035 cmd .PrintUsage ()
@@ -45,27 +40,8 @@ func runAttach(cmd *types.Command, args []string) {
4540
4641 serverID := cmd .API .GetServerID (args [0 ])
4742
48- termjsURL := fmt .Sprintf ("https://tty.cloud.online.net?server_id=%s&type=serial&auth_token=%s" , serverID , cmd .API .Token )
49-
50- log .Debugf ("Executing: %s %s" , termjsBin , termjsURL )
51- // FIXME: check if termjs-cli is installed
52- spawn := exec .Command (termjsBin , termjsURL )
53- spawn .Stdout = os .Stdout
54- spawn .Stdin = os .Stdin
55- spawn .Stderr = os .Stderr
56- err := spawn .Run ()
43+ err := utils .AttachToSerial (serverID , cmd .API .Token )
5744 if err != nil {
58- log .Warnf ("%v" , err )
59- fmt .Fprintf (os .Stderr , `
60- You need to install '%s' from https://github.com/moul/term.js-cli
61-
62- npm install -g term.js-cli
63-
64- However, you can access your serial using a web browser:
65-
66- %s
67-
68- ` , termjsBin , termjsURL )
69- os .Exit (1 )
45+ log .Fatalf ("%v" , err )
7046 }
7147}
0 commit comments