chore: refactor name

main
sudo pacman -Syu 2024-02-17 15:32:41 +07:00
parent bed83cbd66
commit 88742866aa
2 changed files with 62 additions and 62 deletions

View File

@ -22,7 +22,7 @@ func (a *action) runHelp(c *cli.Context) error {
}
func (a *action) runInstall(c *cli.Context) error {
cfg, err := a.loadConfig(c, installCommand)
cfg, err := a.loadConfig(c, commandInstallName)
if err != nil {
return err
}
@ -35,7 +35,7 @@ func (a *action) runInstall(c *cli.Context) error {
}
func (a *action) runUpdate(c *cli.Context) error {
cfg, err := a.loadConfig(c, updateCommand)
cfg, err := a.loadConfig(c, commandUpdateName)
if err != nil {
return err
}
@ -48,7 +48,7 @@ func (a *action) runUpdate(c *cli.Context) error {
}
func (a *action) runDownload(c *cli.Context) error {
cfg, err := a.loadConfig(c, downloadCommand)
cfg, err := a.loadConfig(c, commandDownloadName)
if err != nil {
return err
}
@ -61,7 +61,7 @@ func (a *action) runDownload(c *cli.Context) error {
}
func (a *action) runClean(c *cli.Context) error {
cfg, err := a.loadConfig(c, cleanCommand)
cfg, err := a.loadConfig(c, commandCleanName)
if err != nil {
return err
}
@ -74,7 +74,7 @@ func (a *action) runClean(c *cli.Context) error {
}
func (a *action) runDiff(c *cli.Context) error {
cfg, err := a.loadConfig(c, diffCommand)
cfg, err := a.loadConfig(c, commandDiffName)
if err != nil {
return err
}
@ -87,7 +87,7 @@ func (a *action) runDiff(c *cli.Context) error {
}
func (a *action) runValidate(c *cli.Context) error {
cfg, err := a.loadConfig(c, validateCommand)
cfg, err := a.loadConfig(c, commandValidateName)
if err != nil {
return err
}
@ -117,8 +117,8 @@ func (a *action) loadConfig(c *cli.Context, command string) (config.Config, erro
}
func (a *action) getFlags(c *cli.Context) {
a.flags.verbose = c.Bool(verboseFlag)
a.flags.dryRun = c.Bool(dryRunFlag)
a.flags.verbose = c.Bool(flagVerboseName)
a.flags.dryRun = c.Bool(flagDryRunName)
}
func (a *action) log(format string, v ...interface{}) {

View File

@ -11,32 +11,32 @@ import (
)
const (
appName = "dotfiles"
appUsage = "managing dotfiles"
name = "dotfiles"
usage = "managing dotfiles"
installCommand = "install"
installUsage = "install user configs from dotfiles"
commandInstallName = "install"
commandInstallUsage = "install user configs from dotfiles"
updateCommand = "update"
updateUsage = "update dotfiles from user configs"
commandUpdateName = "update"
commandUpdateUsage = "update dotfiles from user configs"
downloadCommand = "download"
downloadUsage = "download configs from internet (theme for example)"
commandDownloadName = "download"
commandDownloadUsage = "download configs from internet (theme for example)"
cleanCommand = "clean"
cleanUsage = "clean unused dotfiles"
commandCleanName = "clean"
commandCleanUsage = "clean unused dotfiles"
diffCommand = "diff"
diffUsage = "diff dotfiles with user configs"
commandDiffName = "diff"
commandDiffUsage = "diff dotfiles with user configs"
validateCommand = "validate"
validateUsage = "validate config"
commandValidateName = "validate"
commonValidateUsage = "validate config"
verboseFlag = "verbose"
verboseUsage = "show what is going on"
flagVerboseName = "verbose"
flagVerboseUsage = "show what is going on"
dryRunFlag = "dry-run"
dryRunUsage = "demo mode without actually changing anything"
flagDryRunName = "dry-run"
flagDryRunUsage = "demo mode without actually changing anything"
currentDir = "."
)
@ -64,93 +64,93 @@ func NewApp() *App {
a := &action{}
cliApp := &cli.App{
Name: appName,
Usage: appUsage,
Name: name,
Usage: usage,
Commands: []*cli.Command{
{
Name: installCommand,
Name: commandInstallName,
Aliases: installAliases,
Usage: installUsage,
Usage: commandInstallUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
&cli.BoolFlag{
Name: dryRunFlag,
Usage: dryRunUsage,
Name: flagDryRunName,
Usage: flagDryRunUsage,
},
},
Action: a.runInstall,
},
{
Name: updateCommand,
Name: commandUpdateName,
Aliases: updateAliases,
Usage: updateUsage,
Usage: commandUpdateUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
&cli.BoolFlag{
Name: dryRunFlag,
Usage: dryRunUsage,
Name: flagDryRunName,
Usage: flagDryRunUsage,
},
},
Action: a.runUpdate,
},
{
Name: downloadCommand,
Name: commandDownloadName,
Aliases: downloadAliases,
Usage: downloadUsage,
Usage: commandDownloadUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
&cli.BoolFlag{
Name: dryRunFlag,
Usage: dryRunUsage,
Name: flagDryRunName,
Usage: flagDryRunUsage,
},
},
Action: a.runDownload,
},
{
Name: cleanCommand,
Name: commandCleanName,
Aliases: cleanAliases,
Usage: cleanUsage,
Usage: commandCleanUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
&cli.BoolFlag{
Name: dryRunFlag,
Usage: dryRunUsage,
Name: flagDryRunName,
Usage: flagDryRunUsage,
},
},
Action: a.runClean,
},
{
Name: diffCommand,
Name: commandDiffName,
Aliases: diffAliases,
Usage: diffUsage,
Usage: commandDiffUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
},
Action: a.runDiff,
},
{
Name: validateCommand,
Name: commandValidateName,
Aliases: validateAliases,
Usage: validateUsage,
Usage: commonValidateUsage,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: verboseFlag,
Usage: verboseUsage,
Name: flagVerboseName,
Usage: flagVerboseUsage,
},
},
Action: a.runValidate,
@ -167,11 +167,11 @@ func NewApp() *App {
func (a *App) Run() {
// Prevent running at runtime
if _, ok := denyOSes[runtime.GOOS]; ok {
color.PrintAppError(appName, fmt.Sprintf("OS [%s] is not supported right now", runtime.GOOS))
color.PrintAppError(name, fmt.Sprintf("OS [%s] is not supported right now", runtime.GOOS))
return
}
if err := a.cliApp.Run(os.Args); err != nil {
color.PrintAppError(appName, err.Error())
color.PrintAppError(name, err.Error())
}
}