refactor: split generate command and help default
parent
7041b0169f
commit
966b271659
26
main.go
26
main.go
|
@ -12,19 +12,28 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
appName = "license"
|
appName = "license"
|
||||||
appUsage = "generate LICENSE"
|
appUsage = "generate LICENSE quickly"
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
outputFlag = "output"
|
outputFlag = "output"
|
||||||
|
|
||||||
|
// commands
|
||||||
|
generateCommand = "generate"
|
||||||
|
|
||||||
// flag usages
|
// flag usages
|
||||||
outputUsage = "output directory"
|
outputUsage = "output directory"
|
||||||
|
|
||||||
|
// command usages
|
||||||
|
generateUsage = "generate LICENSE"
|
||||||
|
|
||||||
currentDir = "."
|
currentDir = "."
|
||||||
licenseFilename = "LICENSE"
|
licenseFilename = "LICENSE"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// command aliases
|
||||||
|
generateAliases = []string{"gen"}
|
||||||
|
|
||||||
// flag aliases
|
// flag aliases
|
||||||
outputAliases = []string{"o"}
|
outputAliases = []string{"o"}
|
||||||
)
|
)
|
||||||
|
@ -35,6 +44,11 @@ func main() {
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: appName,
|
Name: appName,
|
||||||
Usage: appUsage,
|
Usage: appUsage,
|
||||||
|
Commands: []*cli.Command{
|
||||||
|
{
|
||||||
|
Name: generateCommand,
|
||||||
|
Aliases: generateAliases,
|
||||||
|
Usage: generateUsage,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: outputFlag,
|
Name: outputFlag,
|
||||||
|
@ -43,7 +57,10 @@ func main() {
|
||||||
DefaultText: currentDir,
|
DefaultText: currentDir,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: a.Run,
|
Action: a.RunGenerate,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: a.RunHelp,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
@ -57,12 +74,11 @@ type action struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *action) Run(c *cli.Context) error {
|
func (a *action) RunHelp(c *cli.Context) error {
|
||||||
// Show help if there is nothing
|
|
||||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
|
||||||
return cli.ShowAppHelp(c)
|
return cli.ShowAppHelp(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *action) RunGenerate(c *cli.Context) error {
|
||||||
a.getFlags(c)
|
a.getFlags(c)
|
||||||
|
|
||||||
fmt.Printf("What LICENSE do you chose: ")
|
fmt.Printf("What LICENSE do you chose: ")
|
||||||
|
|
Loading…
Reference in New Issue