aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/mugi/main.go20
-rw-r--r--config.example.yaml8
-rw-r--r--internal/config/config.go32
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
+}