Skip to content

Commit baacde4

Browse files
authored
feat: parallel apply command (#50)
* feat: parallel apply command fix: show general help for --help flag fix: don't append channel if it doesn't exist chore: build against windows and linux * chore: lint
1 parent 25f544b commit baacde4

4 files changed

Lines changed: 40 additions & 10 deletions

File tree

.github/workflows/push.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ on: [push, pull_request]
55
jobs:
66
build:
77
name: Build
8-
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest, windows-latest]
12+
runs-on: ${{ matrix.os }}
913
steps:
1014
- name: Set up Go
1115
uses: actions/setup-go@v2
@@ -26,6 +30,11 @@ jobs:
2630
env:
2731
CGO_ENABLED: 1
2832

33+
- uses: actions/upload-artifact@v4
34+
with:
35+
name: cli-${{ matrix.os }}
36+
path: ficsit-cli
37+
2938
lint:
3039
name: Lint
3140
runs-on: ubuntu-latest

cli/cache/download.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ func DownloadOrCache(cacheKey string, hash string, url string, updates chan<- ut
3434
}
3535
})
3636

37-
_, _ = downloadSync.Compute(cacheKey, func(oldValue *downloadGroup, loaded bool) (*downloadGroup, bool) {
38-
oldValue.updates = append(oldValue.updates, updates)
39-
return oldValue, false
40-
})
37+
if updates != nil {
38+
_, _ = downloadSync.Compute(cacheKey, func(oldValue *downloadGroup, loaded bool) (*downloadGroup, bool) {
39+
oldValue.updates = append(oldValue.updates, updates)
40+
return oldValue, false
41+
})
42+
}
4143

4244
downloadCache := filepath.Join(viper.GetString("cache-dir"), "downloadCache")
4345
if err := os.MkdirAll(downloadCache, 0o777); err != nil {

cmd/apply.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package cmd
22

33
import (
4+
"log/slog"
5+
"os"
6+
"sync"
7+
48
"github.com/spf13/cobra"
59

610
"github.com/satisfactorymodding/ficsit-cli/cli"
@@ -15,6 +19,8 @@ var applyCmd = &cobra.Command{
1519
return err
1620
}
1721

22+
var wg sync.WaitGroup
23+
errored := false
1824
for _, installation := range global.Installations.Installations {
1925
if len(args) > 0 {
2026
found := false
@@ -31,9 +37,21 @@ var applyCmd = &cobra.Command{
3137
}
3238
}
3339

34-
if err := installation.Install(global, nil); err != nil {
35-
return err
36-
}
40+
wg.Add(1)
41+
42+
go func(installation *cli.Installation) {
43+
defer wg.Done()
44+
if err := installation.Install(global, nil); err != nil {
45+
errored = true
46+
slog.Error("installation failed", slog.Any("err", err))
47+
}
48+
}(installation)
49+
}
50+
51+
wg.Wait()
52+
53+
if errored {
54+
os.Exit(1)
3755
}
3856

3957
return nil

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func Execute(version string, commit string) {
9494
cobra.MousetrapHelpText = ""
9595

9696
cli := len(os.Args) >= 2 && os.Args[1] == "cli"
97-
if (len(os.Args) <= 1 || os.Args[1] != "help") && (err != nil || cmd == RootCmd) {
97+
if (len(os.Args) <= 1 || (os.Args[1] != "help" && os.Args[1] != "--help" && os.Args[1] != "-h")) && (err != nil || cmd == RootCmd) {
9898
args := append([]string{"cli"}, os.Args[1:]...)
9999
RootCmd.SetArgs(args)
100100
cli = true
@@ -109,7 +109,8 @@ func Execute(version string, commit string) {
109109
viper.Set("commit", commit)
110110

111111
if err := RootCmd.Execute(); err != nil {
112-
panic(err)
112+
slog.Error(err.Error())
113+
os.Exit(1)
113114
}
114115
}
115116

0 commit comments

Comments
 (0)