diff options
| author | Fuwn <[email protected]> | 2026-01-26 10:31:30 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-26 10:31:35 +0000 |
| commit | 7ed8407a61fd040012b0ccf148c88ea3ef85f99c (patch) | |
| tree | 8a6125719623198037f32b4d33ea3e6b349c7cf4 | |
| parent | docs(README): Add naming wink (diff) | |
| download | mugi-7ed8407a61fd040012b0ccf148c88ea3ef85f99c.tar.xz mugi-7ed8407a61fd040012b0ccf148c88ea3ef85f99c.zip | |
feat(config): Add config-based defaults for verbosity and remotes
| -rw-r--r-- | cmd/mugi/main.go | 20 | ||||
| -rw-r--r-- | config.example.yaml | 8 | ||||
| -rw-r--r-- | internal/config/config.go | 32 |
3 files changed, 58 insertions, 2 deletions
diff --git a/cmd/mugi/main.go b/cmd/mugi/main.go index 76f1c18..3c32db6 100644 --- a/cmd/mugi/main.go +++ b/cmd/mugi/main.go @@ -41,6 +41,8 @@ func run() error { return fmt.Errorf("config: %w", err) } + applyDefaults(&cmd, cfg) + tasks := ui.BuildTasks(cfg, cmd.Repo, cmd.Remotes) if len(tasks) == 0 { return fmt.Errorf("no matching repositories or remotes found") @@ -48,3 +50,21 @@ func run() error { return ui.Run(cmd.Operation, tasks, cmd.Verbose, cmd.Force, cmd.Linear) } + +func applyDefaults(cmd *cli.Command, cfg config.Config) { + if cfg.Defaults.Verbose { + cmd.Verbose = true + } + + if cfg.Defaults.Linear { + cmd.Linear = true + } + + if len(cmd.Remotes) == 1 && cmd.Remotes[0] == "all" { + opRemotes := cfg.Defaults.RemotesFor(cmd.Operation.String()) + + if len(opRemotes) > 0 { + cmd.Remotes = opRemotes + } + } +} diff --git a/config.example.yaml b/config.example.yaml index dc8ce4e..12635c4 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -12,6 +12,14 @@ remotes: defaults: remotes: [github, codeberg, sourcehut] path_prefix: ~/Developer + verbose: false + linear: false + pull: + remotes: [github] + push: + remotes: [github, codeberg, sourcehut] + fetch: + remotes: [github, codeberg, sourcehut] repos: gemrest/windmark: {} diff --git a/internal/config/config.go b/internal/config/config.go index 9564b4e..133d527 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,9 +14,18 @@ type RemoteDefinition struct { URL string `yaml:"url"` } +type OperationDefaults struct { + Remotes []string `yaml:"remotes"` +} + type Defaults struct { - Remotes []string `yaml:"remotes"` - PathPrefix string `yaml:"path_prefix"` + Remotes []string `yaml:"remotes"` + PathPrefix string `yaml:"path_prefix"` + Verbose bool `yaml:"verbose"` + Linear bool `yaml:"linear"` + Pull OperationDefaults `yaml:"pull"` + Push OperationDefaults `yaml:"push"` + Fetch OperationDefaults `yaml:"fetch"` } type RepoRemotes map[string]string @@ -248,3 +257,22 @@ func (r Repo) ExpandPath() string { return path } + +func (d Defaults) RemotesFor(operation string) []string { + switch operation { + case "pull": + if len(d.Pull.Remotes) > 0 { + return d.Pull.Remotes + } + case "push": + if len(d.Push.Remotes) > 0 { + return d.Push.Remotes + } + case "fetch": + if len(d.Fetch.Remotes) > 0 { + return d.Fetch.Remotes + } + } + + return d.Remotes +} |