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