Skip to content

Commit

Permalink
Support of 'scw run -d' option (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 30, 2015
1 parent 4cf44a8 commit b7e3ea0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ Run a command in a new server.

Options:

-a, --attach=false Attach to serial console
--bootscript="" Assign a bootscript
-d, --detach=false Run server in background and print server ID
-e, --env="" Provide metadata tags passed to initrd (i.e., boot=resue INITRD_DEBUG=1)
-h, --help=false Print usage
--name="" Assign a name
Expand All @@ -577,9 +579,11 @@ Options:
Examples:

$ scw run ubuntu-trusty
$ scw run ubuntu-trusty bash
$ scw run --name=mydocker docker docker run moul/nyancat:armhf
$ scw run --bootscript=3.2.34 --env="boot=live rescue_image=http://j.mp/scaleway-ubuntu-trusty-tarball" 50GB bash
$ scw run attach alpine
$ scw run --attach alpine
$ scw run --detach alpine
```


Expand Down Expand Up @@ -1020,7 +1024,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'

#### Features

* No entry
* Support of `scw run -d` option ([#69](https://github.com/scaleway/scaleway-cli/issues/69))

#### Fixes

Expand Down
20 changes: 18 additions & 2 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package commands

import (
"fmt"
"os"
"time"

Expand All @@ -22,9 +23,11 @@ var cmdRun = &types.Command{
Help: "Run a command in a new server.",
Examples: `
$ scw run ubuntu-trusty
$ scw run ubuntu-trusty bash
$ scw run --name=mydocker docker docker run moul/nyancat:armhf
$ scw run --bootscript=3.2.34 --env="boot=live rescue_image=http://j.mp/scaleway-ubuntu-trusty-tarball" 50GB bash
$ scw run attach alpine
$ scw run --attach alpine
$ scw run --detach alpine
`,
}

Expand All @@ -35,6 +38,7 @@ func init() {
cmdRun.Flag.StringVar(&runCreateVolume, []string{"v", "-volume"}, "", "Attach additional volume (i.e., 50G)")
cmdRun.Flag.BoolVar(&runHelpFlag, []string{"h", "-help"}, false, "Print usage")
cmdRun.Flag.BoolVar(&runAttachFlag, []string{"a", "-attach"}, false, "Attach to serial console")
cmdRun.Flag.BoolVar(&runDetachFlag, []string{"d", "-detach"}, false, "Run server in background and print server ID")
// FIXME: handle start --timeout
}

Expand All @@ -45,6 +49,7 @@ var runCreateEnv string // -e, --env flag
var runCreateVolume string // -v, --volume flag
var runHelpFlag bool // -h, --help flag
var runAttachFlag bool // -a, --attach flag
var runDetachFlag bool // -d, --detach flag

func runRun(cmd *types.Command, args []string) {
if runHelpFlag {
Expand All @@ -54,7 +59,13 @@ func runRun(cmd *types.Command, args []string) {
cmd.PrintShortUsage()
}
if runAttachFlag && len(args) > 1 {
log.Fatalf("Cannot use '--attach' and 'COMMAND [ARG...]' at the same time. See 'scw run --help'")
log.Fatalf("Conflicting options: -a and COMMAND")
}
if runAttachFlag && runDetachFlag {
log.Fatalf("Conflicting options: -a and -d")
}
if runDetachFlag && len(args) > 1 {
log.Fatalf("Conflicting options: -d and COMMAND")
}

// create IMAGE
Expand All @@ -73,6 +84,11 @@ func runRun(cmd *types.Command, args []string) {
}
log.Debugf("Server is booting")

if runDetachFlag {
fmt.Println(serverID)
return
}

if runAttachFlag {
// Attach to server serial
log.Debugf("Attaching to server console")
Expand Down

0 comments on commit b7e3ea0

Please sign in to comment.