refactor: read license from input
parent
b783a687b5
commit
5dee297703
15
main.go
15
main.go
|
@ -13,7 +13,6 @@ import (
|
||||||
const (
|
const (
|
||||||
appName = "license"
|
appName = "license"
|
||||||
|
|
||||||
nameFlag = "name"
|
|
||||||
outputFlag = "output"
|
outputFlag = "output"
|
||||||
|
|
||||||
currentDir = "."
|
currentDir = "."
|
||||||
|
@ -29,11 +28,6 @@ func main() {
|
||||||
Name: appName,
|
Name: appName,
|
||||||
Usage: "generate LICENSE",
|
Usage: "generate LICENSE",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
|
||||||
Name: nameFlag,
|
|
||||||
Aliases: []string{"n"},
|
|
||||||
Usage: "which `LICENSE`",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: outputFlag,
|
Name: outputFlag,
|
||||||
Aliases: []string{"o"},
|
Aliases: []string{"o"},
|
||||||
|
@ -53,7 +47,6 @@ func main() {
|
||||||
|
|
||||||
type action struct {
|
type action struct {
|
||||||
flags struct {
|
flags struct {
|
||||||
name string
|
|
||||||
output string
|
output string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,9 +59,12 @@ func (a *action) Run(c *cli.Context) error {
|
||||||
|
|
||||||
a.getFlags(c)
|
a.getFlags(c)
|
||||||
|
|
||||||
license, err := generateLicense(a.flags.name)
|
fmt.Printf("What LICENSE do you chose: ")
|
||||||
|
licenseName := readStdin()
|
||||||
|
|
||||||
|
license, err := generateLicense(licenseName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to generate license %s: %w", a.flags.name, err)
|
return fmt.Errorf("failed to generate license %s: %w", licenseName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFile := filepath.Join(a.flags.output, licenseFilename)
|
outputFile := filepath.Join(a.flags.output, licenseFilename)
|
||||||
|
@ -80,6 +76,5 @@ func (a *action) Run(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *action) getFlags(c *cli.Context) {
|
func (a *action) getFlags(c *cli.Context) {
|
||||||
a.flags.name = c.String(nameFlag)
|
|
||||||
a.flags.output = c.String(outputFlag)
|
a.flags.output = c.String(outputFlag)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue