chore: use cli default
parent
8a55fb5b3d
commit
f6240686ec
|
@ -29,6 +29,7 @@ type action struct {
|
|||
filename string
|
||||
filetype string
|
||||
dryRun bool
|
||||
interactive bool
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,24 +48,16 @@ func (a *action) getFlags(c *cli.Context) {
|
|||
a.flags.scopes[scope] = struct{}{}
|
||||
}
|
||||
|
||||
a.flags.repository = a.getFlagValue(c, flagRepository, defaultRepository)
|
||||
a.flags.output = a.getFlagValue(c, flagOutput, defaultOutput)
|
||||
a.flags.filename = a.getFlagValue(c, flagFilename, defaultFilename)
|
||||
a.flags.filetype = a.getFlagValue(c, flagFiletype, defaultFiletype)
|
||||
a.flags.repository = c.String(flagRepository)
|
||||
a.flags.output = c.String(flagOutput)
|
||||
a.flags.filename = c.String(flagFilename)
|
||||
a.flags.filetype = c.String(flagFiletype)
|
||||
a.flags.dryRun = c.Bool(flagDryRun)
|
||||
a.flags.interactive = c.Bool(flagInteractive)
|
||||
|
||||
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{}) {
|
||||
if a.flags.verbose {
|
||||
log.Printf(format, v...)
|
||||
|
|
|
@ -21,6 +21,7 @@ const (
|
|||
flagFilename = "filename"
|
||||
flagFiletype = "filetype"
|
||||
flagDryRun = "dry-run"
|
||||
flagInteractive = "interactive"
|
||||
|
||||
commandGenerate = "generate"
|
||||
|
||||
|
@ -35,11 +36,13 @@ const (
|
|||
usageFilename = "output `FILENAME`"
|
||||
usageFiletype = "output `FILETYPE`"
|
||||
usageDryRun = "demo run without actually changing anything"
|
||||
usageInteractive = "interactive mode"
|
||||
)
|
||||
|
||||
var (
|
||||
aliasGenerate = []string{"gen"}
|
||||
aliasVerbose = []string{"v"}
|
||||
aliasInteractive = []string{"i"}
|
||||
)
|
||||
|
||||
type App struct {
|
||||
|
@ -82,27 +85,32 @@ func NewApp() *App {
|
|||
&cli.StringFlag{
|
||||
Name: flagRepository,
|
||||
Usage: usageRepository,
|
||||
DefaultText: defaultRepository,
|
||||
Value: defaultRepository,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagOutput,
|
||||
Usage: usageOutput,
|
||||
DefaultText: defaultOutput,
|
||||
Value: defaultOutput,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagFilename,
|
||||
Usage: usageFilename,
|
||||
DefaultText: defaultFilename,
|
||||
Value: defaultFilename,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagFiletype,
|
||||
Usage: usageFiletype,
|
||||
DefaultText: defaultFiletype,
|
||||
Value: defaultFiletype,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: flagDryRun,
|
||||
Usage: usageDryRun,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: flagInteractive,
|
||||
Usage: usageInteractive,
|
||||
Aliases: aliasInteractive,
|
||||
},
|
||||
},
|
||||
Action: a.RunGenerate,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue