refactor: use diff instead of compare

main
sudo pacman -Syu 2022-05-31 16:27:06 +07:00
parent 031091c978
commit d5929acd01
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
6 changed files with 12 additions and 14 deletions

View File

@ -20,6 +20,6 @@ go build ./cmd/dot
## Roadmap ## Roadmap
- [ ] Support compare directory
- [x] Switch to use lua for neovim config - [x] Switch to use lua for neovim config
- [x] Add diff command - [x] Add diff command
- [x] Support diff directory

View File

@ -68,16 +68,16 @@ func (a *action) runClean(c *cli.Context) error {
return nil return nil
} }
func (a *action) runCompare(c *cli.Context) error { func (a *action) runDiff(c *cli.Context) error {
a.getFlags(c) a.getFlags(c)
a.log("start %s\n", compareCommand) a.log("start %s\n", diffCommand)
cfg, err := a.loadConfig() cfg, err := a.loadConfig()
if err != nil { if err != nil {
return err return err
} }
if err := cfg.Compare(); err != nil { if err := cfg.Diff(); err != nil {
return fmt.Errorf("failed to compare config: %w", err) return fmt.Errorf("failed to compare config: %w", err)
} }

View File

@ -21,7 +21,7 @@ const (
installCommand = "install" installCommand = "install"
updateCommand = "update" updateCommand = "update"
cleanCommand = "clean" cleanCommand = "clean"
compareCommand = "compare" diffCommand = "diff"
// flag usages // flag usages
verboseUsage = "show what is going on" verboseUsage = "show what is going on"
@ -31,7 +31,7 @@ const (
installUsage = "install user configs from dotfiles" installUsage = "install user configs from dotfiles"
updateUsage = "update dotfiles from user configs" updateUsage = "update dotfiles from user configs"
cleanUsage = "clean unused dotfiles" cleanUsage = "clean unused dotfiles"
compareUsage = "compare dotfiles with user configs" diffUsage = "diff dotfiles with user configs"
currentDir = "." currentDir = "."
) )
@ -41,7 +41,6 @@ var (
installAliases = []string{"i"} installAliases = []string{"i"}
updateAliases = []string{"u"} updateAliases = []string{"u"}
cleanAliases = []string{"c"} cleanAliases = []string{"c"}
compareAliases = []string{"cmp", "diff"}
) )
// denyOSes contains OS which is not supported // denyOSes contains OS which is not supported
@ -110,16 +109,15 @@ func NewApp() *App {
Action: a.runClean, Action: a.runClean,
}, },
{ {
Name: compareCommand, Name: diffCommand,
Aliases: compareAliases, Usage: diffUsage,
Usage: compareUsage,
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: verboseFlag, Name: verboseFlag,
Usage: verboseUsage, Usage: verboseUsage,
}, },
}, },
Action: a.runCompare, Action: a.runDiff,
}, },
}, },
Action: a.runHelp, Action: a.runHelp,

View File

@ -16,7 +16,7 @@ type Config interface {
Install() error Install() error
Update() error Update() error
Clean() error Clean() error
Compare() error Diff() error
} }
type configApps struct { type configApps struct {

View File

@ -41,6 +41,6 @@ func (c *configDemo) Clean() error {
return nil return nil
} }
func (c *configDemo) Compare() error { func (c *configDemo) Diff() error {
return nil return nil
} }

View File

@ -59,7 +59,7 @@ func (c *configReal) Clean() error {
return nil return nil
} }
func (c *configReal) Compare() error { func (c *configReal) Diff() error {
for _, app := range c.Apps { for _, app := range c.Apps {
for _, p := range app.Paths { for _, p := range app.Paths {
if err := diff.Diff(p.Internal, p.External); err != nil { if err := diff.Diff(p.Internal, p.External); err != nil {