Skip to content

Commit

Permalink
Fix #155: Destroy/Login commands didn't scan lines correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyko0 committed Oct 19, 2015
1 parent e594efd commit 3f156ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions apps/destroy.go
@@ -1,17 +1,21 @@
package apps

import (
"bufio"
"fmt"
"os"

"github.com/Scalingo/cli/Godeps/_workspace/src/github.com/Scalingo/go-scalingo"
"github.com/Scalingo/cli/Godeps/_workspace/src/gopkg.in/errgo.v1"
"github.com/Scalingo/cli/io"
)

func Destroy(appName string) error {
var validationName string
fmt.Printf("/!\\ You're going to delete %s, this operation is irreversible.\nTo confirm type the name of the application: ", appName)
fmt.Scan(&validationName)
validationName, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return errgo.Mask(err, errgo.Any)
}
if validationName != appName {
return errgo.Newf("'%s' is not '%s', aborting…\n", validationName, appName)
}
Expand Down
6 changes: 5 additions & 1 deletion config/auth.go
@@ -1,6 +1,7 @@
package config

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -107,15 +108,18 @@ func (a *CliAuthenticator) RemoveAuth() error {

func tryAuth() (*users.User, error) {
var login string
var err error

for login == "" {
fmt.Print("Username or email: ")
_, err := fmt.Scanln(&login)
login, err = bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
if strings.Contains(err.Error(), "unexpected newline") {
continue
}
return nil, errgo.Mask(err, errgo.Any)
}
login = strings.TrimRight(login, "\n")
}

password, err := term.Password("Password: ")
Expand Down

0 comments on commit 3f156ea

Please sign in to comment.