diff --git a/cmd/control/console.go b/cmd/control/console.go index 61eee2df..088eff84 100644 --- a/cmd/control/console.go +++ b/cmd/control/console.go @@ -1,10 +1,8 @@ package control import ( - "bufio" "fmt" "io/ioutil" - "os" "sort" "strings" @@ -61,12 +59,11 @@ func consoleSwitch(c *cli.Context) error { } if !c.Bool("force") { - in := bufio.NewReader(os.Stdin) fmt.Println(`Switching consoles will 1. destroy the current console container 2. log you out 3. restart Docker`) - if !yes(in, "Continue") { + if !yes("Continue") { return nil } } diff --git a/cmd/control/install.go b/cmd/control/install.go index d26f8191..9e9254cf 100644 --- a/cmd/control/install.go +++ b/cmd/control/install.go @@ -1,7 +1,6 @@ package control import ( - "bufio" "fmt" "os" "os/exec" @@ -22,8 +21,10 @@ var installCommand = cli.Command{ Action: installAction, Flags: []cli.Flag{ cli.StringFlag{ - Name: "image, i", - Usage: "install from a certain image", + // TODO: need to validate ? -i rancher/os:v0.3.1 just sat there. + Name: "image, i", + Usage: `install from a certain image (e.g., 'rancher/os:v0.7.0') + use 'ros os list' to see what versions are available.`, }, cli.StringFlag{ Name: "install-type, t", @@ -97,12 +98,10 @@ func installAction(c *cli.Context) error { } func runInstall(image, installType, cloudConfig, device, append string, force, reboot bool) error { - in := bufio.NewReader(os.Stdin) - fmt.Printf("Installing from %s\n", image) if !force { - if !yes(in, "Continue") { + if !yes("Continue") { os.Exit(1) } } @@ -122,7 +121,7 @@ func runInstall(image, installType, cloudConfig, device, append string, force, r return err } - if reboot && (force || yes(in, "Continue with reboot")) { + if reboot && (force || yes("Continue with reboot")) { log.Info("Rebooting") power.Reboot() } diff --git a/cmd/control/os.go b/cmd/control/os.go index 866a7591..59884f84 100644 --- a/cmd/control/os.go +++ b/cmd/control/os.go @@ -1,7 +1,6 @@ package control import ( - "bufio" "fmt" "io/ioutil" "net/http" @@ -196,8 +195,6 @@ func osVersion(c *cli.Context) error { } func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgradeConsole bool, kernelArgs string) error { - in := bufio.NewReader(os.Stdin) - command := []string{ "-t", "rancher-upgrade", "-r", config.VERSION, @@ -224,7 +221,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra if len(imageSplit) > 1 && imageSplit[1] == config.VERSION+config.SUFFIX { confirmation = fmt.Sprintf("Already at version %s. Continue anyway", imageSplit[1]) } - if !force && !yes(in, confirmation) { + if !force && !yes(confirmation) { os.Exit(1) } @@ -274,7 +271,7 @@ func startUpgradeContainer(image string, stage, force, reboot, kexec bool, upgra return err } - if reboot && (force || yes(in, "Continue with reboot")) { + if reboot && (force || yes("Continue with reboot")) { log.Info("Rebooting") power.Reboot() } diff --git a/cmd/control/util.go b/cmd/control/util.go index 6ab95b67..1c0874e8 100644 --- a/cmd/control/util.go +++ b/cmd/control/util.go @@ -1,16 +1,16 @@ package control import ( - "bufio" "fmt" "strings" log "github.com/Sirupsen/logrus" ) -func yes(in *bufio.Reader, question string) bool { +func yes(question string) bool { fmt.Printf("%s [y/N]: ", question) - line, err := in.ReadString('\n') + var line string + _, err := fmt.Scan(&line) if err != nil { log.Fatal(err) }