aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-26 09:47:11 +0000
committerFuwn <[email protected]>2026-01-26 09:47:11 +0000
commitfe7f87b30173973c7fd54a9e2a9c4ebe4db1a7f4 (patch)
tree76da4bb6c0398bd92b9459469363b4d1977699b0 /internal
parentfeat: Add force push flag (diff)
downloadmugi-fe7f87b30173973c7fd54a9e2a9c4ebe4db1a7f4.tar.xz
mugi-fe7f87b30173973c7fd54a9e2a9c4ebe4db1a7f4.zip
feat: Add linear mode for sequential operations
Diffstat (limited to 'internal')
-rw-r--r--internal/cli/cli.go20
-rw-r--r--internal/ui/ui.go45
2 files changed, 50 insertions, 15 deletions
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 1bee391..306e242 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -16,6 +16,7 @@ type Command struct {
ConfigPath string
Verbose bool
Force bool
+ Linear bool
Help bool
Version bool
}
@@ -36,6 +37,7 @@ func Parse(args []string) (Command, error) {
args, cmd.ConfigPath = extractConfigFlag(args)
args, cmd.Verbose = extractVerboseFlag(args)
args, cmd.Force = extractForceFlag(args)
+ args, cmd.Linear = extractLinearFlag(args)
for _, arg := range args {
if arg == "-h" || arg == "--help" || arg == "help" {
@@ -103,6 +105,7 @@ Flags:
-c, --config <path> Override config file path
-V, --verbose Show detailed output
-f, --force Force push (use with caution)
+ -l, --linear Run operations sequentially
Examples:
mugi pull Pull all repositories from all remotes
@@ -194,3 +197,20 @@ func extractForceFlag(args []string) ([]string, bool) {
return remaining, force
}
+
+func extractLinearFlag(args []string) ([]string, bool) {
+ var remaining []string
+ var linear bool
+
+ for _, arg := range args {
+ if arg == "-l" || arg == "--linear" {
+ linear = true
+
+ continue
+ }
+
+ remaining = append(remaining, arg)
+ }
+
+ return remaining, linear
+}
diff --git a/internal/ui/ui.go b/internal/ui/ui.go
index e6e6ab2..45e0992 100644
--- a/internal/ui/ui.go
+++ b/internal/ui/ui.go
@@ -38,17 +38,19 @@ type taskResult struct {
}
type Model struct {
- tasks []Task
- states map[string]taskState
- results map[string]git.Result
- spinner spinner.Model
- operation remote.Operation
- verbose bool
- force bool
- done bool
-}
-
-func NewModel(op remote.Operation, tasks []Task, verbose, force bool) Model {
+ tasks []Task
+ states map[string]taskState
+ results map[string]git.Result
+ spinner spinner.Model
+ operation remote.Operation
+ verbose bool
+ force bool
+ linear bool
+ currentTask int
+ done bool
+}
+
+func NewModel(op remote.Operation, tasks []Task, verbose, force, linear bool) Model {
s := spinner.New()
s.Spinner = spinner.Dot
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
@@ -67,6 +69,7 @@ func NewModel(op remote.Operation, tasks []Task, verbose, force bool) Model {
operation: op,
verbose: verbose,
force: force,
+ linear: linear,
}
}
@@ -77,8 +80,14 @@ func taskKey(t Task) string {
func (m Model) Init() tea.Cmd {
cmds := []tea.Cmd{m.spinner.Tick}
- for _, task := range m.tasks {
- cmds = append(cmds, m.runTask(task))
+ if m.linear {
+ if len(m.tasks) > 0 {
+ cmds = append(cmds, m.runTask(m.tasks[0]))
+ }
+ } else {
+ for _, task := range m.tasks {
+ cmds = append(cmds, m.runTask(task))
+ }
}
return tea.Batch(cmds...)
@@ -106,11 +115,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.states[key] = taskSuccess
}
m.results[key] = msg.result
+ m.currentTask++
if m.allDone() {
m.done = true
+
return m, tea.Quit
}
+
+ if m.linear && m.currentTask < len(m.tasks) {
+ return m, m.runTask(m.tasks[m.currentTask])
+ }
}
return m, nil
@@ -228,7 +243,7 @@ func indentOutput(s string, style lipgloss.Style) string {
return strings.Join(lines, "\n")
}
-func Run(op remote.Operation, tasks []Task, verbose, force bool) error {
+func Run(op remote.Operation, tasks []Task, verbose, force, linear bool) error {
if op == remote.Pull {
inits := NeedsInit(tasks)
if len(inits) > 0 {
@@ -244,7 +259,7 @@ func Run(op remote.Operation, tasks []Task, verbose, force bool) error {
tasks = adjustPullTasks(tasks)
}
- model := NewModel(op, tasks, verbose, force)
+ model := NewModel(op, tasks, verbose, force, linear)
p := tea.NewProgram(model)
_, err := p.Run()