refactor: use prefixName and prefixUsage

main
sudo pacman -Syu 2022-08-16 12:54:20 +07:00
parent 38114a30c1
commit 75d135bf95
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 14 additions and 20 deletions

34
main.go
View File

@ -11,20 +11,14 @@ import (
) )
const ( const (
appName = "license" name = "license"
appUsage = "generate LICENSE quickly" usage = "generate LICENSE quickly"
// flags commandGenerateName = "generate"
outputFlag = "output" commandGenerateUsage = "generate LICENSE"
// commands flagOutputName = "output"
generateCommand = "generate" flagOutputUsage = "output directory"
// flag usages
outputUsage = "output directory"
// command usages
generateUsage = "generate LICENSE"
currentDir = "." currentDir = "."
licenseFilename = "LICENSE" licenseFilename = "LICENSE"
@ -42,18 +36,18 @@ func main() {
a := action{} a := action{}
app := &cli.App{ app := &cli.App{
Name: appName, Name: name,
Usage: appUsage, Usage: usage,
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: generateCommand, Name: commandGenerateName,
Aliases: generateAliases, Aliases: generateAliases,
Usage: generateUsage, Usage: commandGenerateUsage,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: outputFlag, Name: flagOutputName,
Aliases: outputAliases, Aliases: outputAliases,
Usage: outputUsage, Usage: flagOutputUsage,
DefaultText: currentDir, DefaultText: currentDir,
}, },
}, },
@ -64,7 +58,7 @@ func main() {
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
color.PrintAppError(appName, err.Error()) color.PrintAppError(name, err.Error())
} }
} }
@ -98,5 +92,5 @@ func (a *action) RunGenerate(c *cli.Context) error {
} }
func (a *action) getFlags(c *cli.Context) { func (a *action) getFlags(c *cli.Context) {
a.flags.output = c.String(outputFlag) a.flags.output = c.String(flagOutputName)
} }