-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update-all: create update-all subcommand
The 'update-all' subcommand runs the 'update' subcommand on all registered routes.
- Loading branch information
1 parent
2930f2b
commit 659370b
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ func all() []Subcommand { | |
return []Subcommand{ | ||
Init{}, | ||
Update{}, | ||
UpdateAll{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |