Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions commands/dotfiles_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ func pullDotfiles(c *cli.Context) error {

// Initialize all available app handlers
allApps := map[string]model.DotfileApp{
"nvim": model.NewNvimApp(),
"fish": model.NewFishApp(),
"git": model.NewGitApp(),
"zsh": model.NewZshApp(),
"bash": model.NewBashApp(),
"ghostty": model.NewGhosttyApp(),
"claude": model.NewClaudeApp(),
"starship": model.NewStarshipApp(),
"nvim": model.NewNvimApp(),
"fish": model.NewFishApp(),
"git": model.NewGitApp(),
"zsh": model.NewZshApp(),
"bash": model.NewBashApp(),
"ghostty": model.NewGhosttyApp(),
"claude": model.NewClaudeApp(),
"starship": model.NewStarshipApp(),
"npm": model.NewNpmApp(),
"ssh": model.NewSshApp(),
"kitty": model.NewKittyApp(),
"kubernetes": model.NewKubernetesApp(),
}

// Process fetched dotfiles
Expand Down
4 changes: 4 additions & 0 deletions commands/dotfiles_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func pushDotfiles(c *cli.Context) error {
model.NewGhosttyApp(),
model.NewClaudeApp(),
model.NewStarshipApp(),
model.NewNpmApp(),
model.NewSshApp(),
model.NewKittyApp(),
model.NewKubernetesApp(),
}

// Filter apps based on user input
Expand Down
26 changes: 26 additions & 0 deletions model/dotfile_kitty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package model

import "context"

// KittyApp handles Kitty terminal configuration files
type KittyApp struct {
BaseApp
}

func NewKittyApp() DotfileApp {
return &KittyApp{}
}

func (k *KittyApp) Name() string {
return "kitty"
}

func (k *KittyApp) GetConfigPaths() []string {
return []string{
"~/.config/kitty/",
}
}

func (k *KittyApp) CollectDotfiles(ctx context.Context) ([]DotfileItem, error) {
return k.CollectFromPaths(ctx, k.Name(), k.GetConfigPaths())
}
Comment on lines +1 to +26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This file, along with dotfile_kubernetes.go, dotfile_npm.go, and dotfile_ssh.go, contains a lot of boilerplate code. All these new application implementations are almost identical, only differing in the application name and configuration paths. This pattern will make it cumbersome to add more simple applications in the future.

To improve maintainability and reduce code duplication, I suggest creating a generic DotfileApp implementation that can be configured with a name and paths. For example:

// In model/dotfile_apps.go or a new file
type ConfigurableApp struct {
	BaseApp
	appName     string
	configPaths []string
}

func NewConfigurableApp(name string, paths []string) DotfileApp {
	return &ConfigurableApp{
		appName:     name,
		configPaths: paths,
	}
}

func (a *ConfigurableApp) Name() string {
	return a.appName
}

func (a *ConfigurableApp) GetConfigPaths() []string {
	return a.configPaths
}

func (a *ConfigurableApp) CollectDotfiles(ctx context.Context) ([]DotfileItem, error) {
	return a.CollectFromPaths(ctx, a.Name(), a.GetConfigPaths())
}

With this, you could remove the new dotfile_*.go files and instantiate the apps directly where they are needed, for example in commands/dotfiles_pull.go:

// ...
"kitty":      model.NewConfigurableApp("kitty", []string{"~/.config/kitty/"}),
"kubernetes": model.NewConfigurableApp("kubernetes", []string{"~/.kube/config"}),
// ...

This would significantly simplify adding new applications that follow this simple file/directory pattern.

26 changes: 26 additions & 0 deletions model/dotfile_kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package model

import "context"

// KubernetesApp handles Kubernetes configuration files
type KubernetesApp struct {
BaseApp
}

func NewKubernetesApp() DotfileApp {
return &KubernetesApp{}
}

func (k *KubernetesApp) Name() string {
return "kubernetes"
}

func (k *KubernetesApp) GetConfigPaths() []string {
return []string{
"~/.kube/config",
}
}

func (k *KubernetesApp) CollectDotfiles(ctx context.Context) ([]DotfileItem, error) {
return k.CollectFromPaths(ctx, k.Name(), k.GetConfigPaths())
}
26 changes: 26 additions & 0 deletions model/dotfile_npm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package model

import "context"

// NpmApp handles npm configuration files
type NpmApp struct {
BaseApp
}

func NewNpmApp() DotfileApp {
return &NpmApp{}
}

func (n *NpmApp) Name() string {
return "npm"
}

func (n *NpmApp) GetConfigPaths() []string {
return []string{
"~/.npmrc",
}
}

func (n *NpmApp) CollectDotfiles(ctx context.Context) ([]DotfileItem, error) {
return n.CollectFromPaths(ctx, n.Name(), n.GetConfigPaths())
}
26 changes: 26 additions & 0 deletions model/dotfile_ssh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package model

import "context"

// SshApp handles SSH configuration files
type SshApp struct {
BaseApp
}

func NewSshApp() DotfileApp {
return &SshApp{}
}

func (s *SshApp) Name() string {
return "ssh"
}

func (s *SshApp) GetConfigPaths() []string {
return []string{
"~/.ssh/config",
}
}

func (s *SshApp) CollectDotfiles(ctx context.Context) ([]DotfileItem, error) {
return s.CollectFromPaths(ctx, s.Name(), s.GetConfigPaths())
}
Loading