From 0f1b9f6bd18ecbccca1be9745423d749ed667c49 Mon Sep 17 00:00:00 2001 From: Tran Hau Date: Sat, 17 Apr 2021 00:31:57 +0700 Subject: [PATCH] feat: using ioe.ReadInput to replace readStdin --- go.mod | 1 + go.sum | 2 ++ license.go | 4 +++- main.go | 3 ++- stdin.go | 24 ------------------------ 5 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 stdin.go diff --git a/go.mod b/go.mod index a42fe64..e543ff9 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,6 @@ go 1.16 require ( github.com/fatih/color v1.10.0 + github.com/haunt98/ioe-go v0.2.0 github.com/urfave/cli/v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 4586904..72ab62e 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSY github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/haunt98/ioe-go v0.2.0 h1:H9jzfzx5pQDg6sC4qnRdb+L0/GyouEYIwJfWH+peEIQ= +github.com/haunt98/ioe-go v0.2.0/go.mod h1:wZNaHPu1gBLTU9KSn8m/QpLiBQI9qf4vnUyNLuMbDtE= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= diff --git a/license.go b/license.go index 4eca229..8906dda 100644 --- a/license.go +++ b/license.go @@ -5,6 +5,8 @@ import ( "fmt" "path/filepath" "strings" + + "github.com/haunt98/ioe-go" ) const ( @@ -55,7 +57,7 @@ func generateLicense(name string) (string, error) { template := string(templateRaw) for _, arg := range templateInfo.args { fmt.Printf("What is your %s: ", arg) - value := readStdin() + value := ioe.ReadInput() template = strings.ReplaceAll(template, arg, value) } diff --git a/main.go b/main.go index 39049e0..baaf1d4 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/fatih/color" + "github.com/haunt98/ioe-go" "github.com/urfave/cli/v2" ) @@ -59,7 +60,7 @@ func (a *action) Run(c *cli.Context) error { a.getFlags(c) fmt.Printf("What LICENSE do you chose: ") - licenseName := readStdin() + licenseName := ioe.ReadInput() license, err := generateLicense(licenseName) if err != nil { diff --git a/stdin.go b/stdin.go deleted file mode 100644 index 2bc81cd..0000000 --- a/stdin.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "bufio" - "os" - "strings" -) - -// Read input until newline, -// ignore empty line -func readStdin() string { - bs := bufio.NewScanner(os.Stdin) - for bs.Scan() { - line := bs.Text() - line = strings.TrimSpace(line) - if line == "" { - continue - } - - return line - } - - return "" -}