From 56b662b032ec75b9c9e29dee6aae83b47dfec45c Mon Sep 17 00:00:00 2001 From: reugn Date: Fri, 27 Aug 2021 13:18:45 +0300 Subject: [PATCH 1/2] move goreleaser configuration --- .github/.goreleaser.yml => .goreleaser.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/.goreleaser.yml => .goreleaser.yml (100%) diff --git a/.github/.goreleaser.yml b/.goreleaser.yml similarity index 100% rename from .github/.goreleaser.yml rename to .goreleaser.yml From 774fcbafadc53280dfa561af14d726414ed75aff Mon Sep 17 00:00:00 2001 From: reugn Date: Fri, 27 Aug 2021 13:20:45 +0300 Subject: [PATCH 2/2] use bufio to read from console --- cmd/wifiqr/main.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/wifiqr/main.go b/cmd/wifiqr/main.go index 66b378e..ab86ad6 100644 --- a/cmd/wifiqr/main.go +++ b/cmd/wifiqr/main.go @@ -1,15 +1,17 @@ package main import ( + "bufio" "flag" "fmt" "os" "path/filepath" + "strings" "github.com/reugn/wifiqr" ) -const version = "0.2.0" +const version = "0.2.1" var ( versionParam = flag.Bool("version", false, "Show version.") @@ -36,7 +38,7 @@ func main() { config := wifiqr.NewConfig(*ssidParam, *keyParam, *encParam, *hiddenParam) q, err := wifiqr.InitCode(config) if err != nil { - fmt.Println(err) + fmt.Fprintf(os.Stderr, "error: %v\n", err) return } @@ -46,12 +48,11 @@ func main() { fileName := validateAndGetFileName() err := q.WriteFile(*sizeParam, fileName) if err != nil { - fmt.Println(err) + fmt.Fprintf(os.Stderr, "error: %v\n", err) } else { fmt.Println("QR Code was successfully saved to " + fileName + ".") } } - } func validateAndGetFileName() string { @@ -64,14 +65,26 @@ func validateAndGetFileName() string { func validateArguments() { if *ssidParam == "" { fmt.Println("Enter the name of the wireless network (SSID):") - fmt.Scan(ssidParam) + *ssidParam = readLine() } if *keyParam == "" { fmt.Println("Enter the network key (password):") - fmt.Scan(keyParam) + *keyParam = readLine() } if *ssidParam == "" || *keyParam == "" { flag.Usage() os.Exit(1) } } + +func readLine() string { + reader := bufio.NewReader(os.Stdin) + line, err := reader.ReadString('\n') + if err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) + } + // convert CRLF to LF + line = strings.Replace(line, "\n", "", -1) + return line +}