Skip to content

Commit bbe9158

Browse files
authored
Merge pull request #3 from reugn/develop
v0.2.1
2 parents cc2ccec + 774fcba commit bbe9158

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
File renamed without changes.

cmd/wifiqr/main.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package main
22

33
import (
4+
"bufio"
45
"flag"
56
"fmt"
67
"os"
78
"path/filepath"
9+
"strings"
810

911
"github.com/reugn/wifiqr"
1012
)
1113

12-
const version = "0.2.0"
14+
const version = "0.2.1"
1315

1416
var (
1517
versionParam = flag.Bool("version", false, "Show version.")
@@ -36,7 +38,7 @@ func main() {
3638
config := wifiqr.NewConfig(*ssidParam, *keyParam, *encParam, *hiddenParam)
3739
q, err := wifiqr.InitCode(config)
3840
if err != nil {
39-
fmt.Println(err)
41+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
4042
return
4143
}
4244

@@ -46,12 +48,11 @@ func main() {
4648
fileName := validateAndGetFileName()
4749
err := q.WriteFile(*sizeParam, fileName)
4850
if err != nil {
49-
fmt.Println(err)
51+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
5052
} else {
5153
fmt.Println("QR Code was successfully saved to " + fileName + ".")
5254
}
5355
}
54-
5556
}
5657

5758
func validateAndGetFileName() string {
@@ -64,14 +65,26 @@ func validateAndGetFileName() string {
6465
func validateArguments() {
6566
if *ssidParam == "" {
6667
fmt.Println("Enter the name of the wireless network (SSID):")
67-
fmt.Scan(ssidParam)
68+
*ssidParam = readLine()
6869
}
6970
if *keyParam == "" {
7071
fmt.Println("Enter the network key (password):")
71-
fmt.Scan(keyParam)
72+
*keyParam = readLine()
7273
}
7374
if *ssidParam == "" || *keyParam == "" {
7475
flag.Usage()
7576
os.Exit(1)
7677
}
7778
}
79+
80+
func readLine() string {
81+
reader := bufio.NewReader(os.Stdin)
82+
line, err := reader.ReadString('\n')
83+
if err != nil {
84+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
85+
os.Exit(1)
86+
}
87+
// convert CRLF to LF
88+
line = strings.Replace(line, "\n", "", -1)
89+
return line
90+
}

0 commit comments

Comments
 (0)