1
0
mirror of https://github.com/rancher/os.git synced 2025-09-16 06:59:12 +00:00

Merge pull request #1316 from SvenDowideit/refactor-yes

Moved NewReader into yes(prompt)
This commit is contained in:
Sven Dowideit
2016-10-21 13:48:19 -07:00
committed by GitHub
4 changed files with 12 additions and 19 deletions

View File

@@ -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
}
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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)
}