chore: use cli default

main
sudo pacman -Syu 2022-02-07 21:22:20 +07:00
parent 8a55fb5b3d
commit f6240686ec
2 changed files with 59 additions and 58 deletions

View File

@ -19,16 +19,17 @@ const (
type action struct { type action struct {
flags struct { flags struct {
verbose bool verbose bool
from string from string
to string to string
version string version string
scopes map[string]struct{} scopes map[string]struct{}
repository string repository string
output string output string
filename string filename string
filetype string filetype string
dryRun bool dryRun bool
interactive bool
} }
} }
@ -47,24 +48,16 @@ func (a *action) getFlags(c *cli.Context) {
a.flags.scopes[scope] = struct{}{} a.flags.scopes[scope] = struct{}{}
} }
a.flags.repository = a.getFlagValue(c, flagRepository, defaultRepository) a.flags.repository = c.String(flagRepository)
a.flags.output = a.getFlagValue(c, flagOutput, defaultOutput) a.flags.output = c.String(flagOutput)
a.flags.filename = a.getFlagValue(c, flagFilename, defaultFilename) a.flags.filename = c.String(flagFilename)
a.flags.filetype = a.getFlagValue(c, flagFiletype, defaultFiletype) a.flags.filetype = c.String(flagFiletype)
a.flags.dryRun = c.Bool(flagDryRun) a.flags.dryRun = c.Bool(flagDryRun)
a.flags.interactive = c.Bool(flagInteractive)
a.log("flags %+v", a.flags) a.log("flags %+v", a.flags)
} }
func (a *action) getFlagValue(c *cli.Context, flag, fallback string) string {
value := c.String(flag)
if value == "" {
value = fallback
}
return value
}
func (a *action) log(format string, v ...interface{}) { func (a *action) log(format string, v ...interface{}) {
if a.flags.verbose { if a.flags.verbose {
log.Printf(format, v...) log.Printf(format, v...)

View File

@ -11,35 +11,38 @@ const (
name = "changeloguru" name = "changeloguru"
usage = "generate changelog from conventional commits" usage = "generate changelog from conventional commits"
flagVerbose = "verbose" flagVerbose = "verbose"
flagFrom = "from" flagFrom = "from"
flagTo = "to" flagTo = "to"
flagVersion = "version" flagVersion = "version"
flagScope = "scope" flagScope = "scope"
flagRepository = "repository" flagRepository = "repository"
flagOutput = "output" flagOutput = "output"
flagFilename = "filename" flagFilename = "filename"
flagFiletype = "filetype" flagFiletype = "filetype"
flagDryRun = "dry-run" flagDryRun = "dry-run"
flagInteractive = "interactive"
commandGenerate = "generate" commandGenerate = "generate"
usageGenerate = "generate changelog" usageGenerate = "generate changelog"
usageVerbose = "show what is going on" usageVerbose = "show what is going on"
usageFrom = "from `COMMIT`, which is kinda new commit" usageFrom = "from `COMMIT`, which is kinda new commit"
usageTo = "to `COMMIT`, which is kinda old commit" usageTo = "to `COMMIT`, which is kinda old commit"
usageVersion = "`VERSION` to generate, follow Semantic Versioning" usageVersion = "`VERSION` to generate, follow Semantic Versioning"
usageScope = "scope to generate" usageScope = "scope to generate"
usageRepository = "`REPOSITORY` directory path" usageRepository = "`REPOSITORY` directory path"
usageOutput = "`OUTPUT` directory path" usageOutput = "`OUTPUT` directory path"
usageFilename = "output `FILENAME`" usageFilename = "output `FILENAME`"
usageFiletype = "output `FILETYPE`" usageFiletype = "output `FILETYPE`"
usageDryRun = "demo run without actually changing anything" usageDryRun = "demo run without actually changing anything"
usageInteractive = "interactive mode"
) )
var ( var (
aliasGenerate = []string{"gen"} aliasGenerate = []string{"gen"}
aliasVerbose = []string{"v"} aliasVerbose = []string{"v"}
aliasInteractive = []string{"i"}
) )
type App struct { type App struct {
@ -80,29 +83,34 @@ func NewApp() *App {
Usage: usageScope, Usage: usageScope,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: flagRepository, Name: flagRepository,
Usage: usageRepository, Usage: usageRepository,
DefaultText: defaultRepository, Value: defaultRepository,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: flagOutput, Name: flagOutput,
Usage: usageOutput, Usage: usageOutput,
DefaultText: defaultOutput, Value: defaultOutput,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: flagFilename, Name: flagFilename,
Usage: usageFilename, Usage: usageFilename,
DefaultText: defaultFilename, Value: defaultFilename,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: flagFiletype, Name: flagFiletype,
Usage: usageFiletype, Usage: usageFiletype,
DefaultText: defaultFiletype, Value: defaultFiletype,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: flagDryRun, Name: flagDryRun,
Usage: usageDryRun, Usage: usageDryRun,
}, },
&cli.BoolFlag{
Name: flagInteractive,
Usage: usageInteractive,
Aliases: aliasInteractive,
},
}, },
Action: a.RunGenerate, Action: a.RunGenerate,
}, },