diff --git a/qrcode/main.go b/qrcode/main.go index ab7c8d8..e0b1e6f 100644 --- a/qrcode/main.go +++ b/qrcode/main.go @@ -10,9 +10,11 @@ import ( "strings" qrcode "github.com/skip2/go-qrcode" + "io/ioutil" ) func main() { + inFile := flag.String("i", "", "content file, empty for STDIN") outFile := flag.String("o", "", "out PNG file prefix, empty for stdout") size := flag.Int("s", 256, "image size (pixel)") flag.Usage = func() { @@ -41,12 +43,25 @@ Usage: if *size <= 0 { checkError(fmt.Errorf("Error: value of -s should > 0")) } - if len(flag.Args()) == 0 { - flag.Usage() - checkError(fmt.Errorf("Error: no content given")) - } content := strings.Join(flag.Args(), " ") + if *inFile != "" { + b, err := ioutil.ReadFile(*inFile) + if err != nil { + checkError(err) + } + content += string(b) + } else { + b, err := ioutil.ReadAll(os.Stdin) + if err != nil { + checkError(err) + } + content += string(b) + } + if content == "" { + flag.Usage() + checkError(fmt.Errorf("Error: no content given?")) + } var err error var q *qrcode.QRCode