feat: using ioe.ReadInput to replace readStdin

main
Tran Hau 2021-04-17 00:31:57 +07:00
parent 100e8a249d
commit 0f1b9f6bd1
5 changed files with 8 additions and 26 deletions

1
go.mod
View File

@ -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
)

2
go.sum
View File

@ -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=

View File

@ -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)
}

View File

@ -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 {

View File

@ -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 ""
}