chore: refactor naming, with purpose prefix

main
sudo pacman -Syu 2022-02-07 20:59:20 +07:00
parent d89f22fce9
commit a9bba2b839
2 changed files with 59 additions and 64 deletions

View File

@ -37,21 +37,21 @@ func (a *action) RunHelp(c *cli.Context) error {
} }
func (a *action) getFlags(c *cli.Context) { func (a *action) getFlags(c *cli.Context) {
a.flags.verbose = c.Bool(verboseFlag) a.flags.verbose = c.Bool(flagVerbose)
a.flags.from = c.String(fromFlag) a.flags.from = c.String(flagFrom)
a.flags.to = c.String(toFlag) a.flags.to = c.String(flagTo)
a.flags.version = c.String(versionFlag) a.flags.version = c.String(flagVersion)
a.flags.scopes = make(map[string]struct{}) a.flags.scopes = make(map[string]struct{})
for _, scope := range c.StringSlice(scopeFlag) { for _, scope := range c.StringSlice(flagScope) {
a.flags.scopes[scope] = struct{}{} a.flags.scopes[scope] = struct{}{}
} }
a.flags.repository = a.getFlagValue(c, repositoryFlag, defaultRepository) a.flags.repository = a.getFlagValue(c, flagRepository, defaultRepository)
a.flags.output = a.getFlagValue(c, outputFlag, defaultOutput) a.flags.output = a.getFlagValue(c, flagOutput, defaultOutput)
a.flags.filename = a.getFlagValue(c, filenameFlag, defaultFilename) a.flags.filename = a.getFlagValue(c, flagFilename, defaultFilename)
a.flags.filetype = a.getFlagValue(c, filetypeFlag, defaultFiletype) a.flags.filetype = a.getFlagValue(c, flagFiletype, defaultFiletype)
a.flags.dryRun = c.Bool(dryRunFlag) a.flags.dryRun = c.Bool(flagDryRun)
a.log("flags %+v", a.flags) a.log("flags %+v", a.flags)
} }

View File

@ -8,38 +8,33 @@ import (
) )
const ( const (
appName = "changeloguru" name = "changeloguru"
appUsage = "generate changelog from conventional commits" usage = "generate changelog from conventional commits"
// flags flagVerbose = "verbose"
verboseFlag = "verbose" flagFrom = "from"
fromFlag = "from" flagTo = "to"
toFlag = "to" flagVersion = "version"
versionFlag = "version" flagScope = "scope"
scopeFlag = "scope" flagRepository = "repository"
repositoryFlag = "repository" flagOutput = "output"
outputFlag = "output" flagFilename = "filename"
filenameFlag = "filename" flagFiletype = "filetype"
filetypeFlag = "filetype" flagDryRun = "dry-run"
dryRunFlag = "dry-run"
// commands commandGenerate = "generate"
generateCommand = "generate"
// flag usage usageGenerate = "generate changelog"
verboseUsage = "show what is going on" usageVerbose = "show what is going on"
fromUsage = "generate from `COMMIT`" usageFrom = "from `COMMIT`, which is kinda new commit"
toUsage = "generate to `COMMIT`" usageTo = "to `COMMIT`, which is kinda old commit"
versionUsage = "`VERSION` to generate, follow Semantic Versioning" usageVersion = "`VERSION` to generate, follow Semantic Versioning"
scopeUsage = "scope to generate" usageScope = "scope to generate"
repositoryUsage = "`REPOSITORY` directory path" usageRepository = "`REPOSITORY` directory path"
outputUsage = "`OUTPUT` directory path" usageOutput = "`OUTPUT` directory path"
filenameUsage = "output `FILENAME`" usageFilename = "output `FILENAME`"
filetypeUsage = "output `FILETYPE`" usageFiletype = "output `FILETYPE`"
dryRunUsage = "demo run without actually changing anything" usageDryRun = "demo run without actually changing anything"
// command usage
generateUsage = "generate changelog"
) )
var ( var (
@ -58,58 +53,58 @@ func NewApp() *App {
a := &action{} a := &action{}
cliApp := &cli.App{ cliApp := &cli.App{
Name: appName, Name: name,
Usage: appUsage, Usage: usage,
Commands: []*cli.Command{ Commands: []*cli.Command{
{ {
Name: generateCommand, Name: commandGenerate,
Aliases: generateAliases, Aliases: generateAliases,
Usage: generateUsage, Usage: usageGenerate,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: verboseFlag, Name: flagVerbose,
Aliases: verboseAliases, Aliases: verboseAliases,
Usage: verboseUsage, Usage: usageVerbose,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: fromFlag, Name: flagFrom,
Usage: fromUsage, Usage: usageFrom,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: toFlag, Name: flagTo,
Usage: toUsage, Usage: usageTo,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: versionFlag, Name: flagVersion,
Usage: versionUsage, Usage: usageVersion,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: scopeFlag, Name: flagScope,
Usage: scopeUsage, Usage: usageScope,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: repositoryFlag, Name: flagRepository,
Usage: repositoryUsage, Usage: usageRepository,
DefaultText: defaultRepository, DefaultText: defaultRepository,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: outputFlag, Name: flagOutput,
Usage: outputUsage, Usage: usageOutput,
DefaultText: defaultOutput, DefaultText: defaultOutput,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: filenameFlag, Name: flagFilename,
Usage: filenameUsage, Usage: usageFilename,
DefaultText: defaultFilename, DefaultText: defaultFilename,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: filetypeFlag, Name: flagFiletype,
Usage: filetypeUsage, Usage: usageFiletype,
DefaultText: defaultFiletype, DefaultText: defaultFiletype,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: dryRunFlag, Name: flagDryRun,
Usage: dryRunUsage, Usage: usageDryRun,
}, },
}, },
Action: a.RunGenerate, Action: a.RunGenerate,
@ -125,6 +120,6 @@ func NewApp() *App {
func (a *App) Run() { func (a *App) Run() {
if err := a.cliApp.Run(os.Args); err != nil { if err := a.cliApp.Run(os.Args); err != nil {
color.PrintAppError(appName, err.Error()) color.PrintAppError(name, err.Error())
} }
} }