fix(cli): read whole password lines from stdin
1 files changed, +8 −4
- main.go modified +8 −4
main.go modified
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | package main |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | + "bufio" | |
| 4 | 5 | "flag" |
| 5 | 6 | "fmt" |
| 6 | 7 | "log" |
| @@ -100,8 +101,7 @@ func main() { | ||
| 100 | 101 | os.Exit(2) |
| 101 | 102 | } |
| 102 | 103 | store := mustStore(*root) |
| 103 | - var password string | |
| 104 | - fmt.Fscanln(os.Stdin, &password) | |
| 104 | + password := readLine() | |
| 105 | 105 | if _, err := store.CreateUser(args[1], password); err != nil { |
| 106 | 106 | log.Fatal(err) |
| 107 | 107 | } |
| @@ -114,8 +114,7 @@ func main() { | ||
| 114 | 114 | if err != nil { |
| 115 | 115 | log.Fatal("no such user") |
| 116 | 116 | } |
| 117 | - var password string | |
| 118 | - fmt.Fscanln(os.Stdin, &password) | |
| 117 | + password := readLine() | |
| 119 | 118 | if err := store.SetPassword(u.ID, password); err != nil { |
| 120 | 119 | log.Fatal(err) |
| 121 | 120 | } |
| @@ -242,3 +241,8 @@ func serve(root string, args []string) { | ||
| 242 | 241 | log.Printf("gitpocket listening on %s for %s", *listen, *host) |
| 243 | 242 | log.Fatal(srv.ListenAndServe()) |
| 244 | 243 | } |
| 244 | + | |
| 245 | +func readLine() string { | |
| 246 | + line, _ := bufio.NewReader(os.Stdin).ReadString('\n') | |
| 247 | + return strings.TrimRight(line, "\r\n") | |
| 248 | +} | |