Skip to content

Commit

Permalink
update-all: create update-all subcommand
Browse files Browse the repository at this point in the history
The 'update-all' subcommand runs the 'update' subcommand on all
registered routes.
  • Loading branch information
derrickstolee committed Aug 25, 2022
1 parent 2930f2b commit 659370b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/git-bundle-server/subcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ func all() []Subcommand {
return []Subcommand{
Init{},
Update{},
UpdateAll{},
}
}
44 changes: 44 additions & 0 deletions cmd/git-bundle-server/update-all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"git-bundle-server/internal/core"
"os"
"os/exec"
)

type UpdateAll struct{}

func (UpdateAll) subcommand() string {
return "update-all"
}

func (UpdateAll) run(args []string) error {
exe, err := os.Executable()
if err != nil {
return fmt.Errorf("failed to get path to execuable: %w", err)
}

repos, err := core.GetRepositories()
if err != nil {
return err
}

for route := range repos {
cmd := exec.Command(exe, "update", route)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

err := cmd.Start()
if err != nil {
return fmt.Errorf("git command failed to start: %w", err)
}

err = cmd.Wait()
if err != nil {
return fmt.Errorf("git command returned a failure: %w", err)
}
}

return nil
}

0 comments on commit 659370b

Please sign in to comment.