Skip to content

Commit

Permalink
feat: parallel apply command (#50)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Vilsol authored Dec 20, 2023
1 parent 25f544b commit baacde4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ on: [push, pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go
uses: actions/setup-go@v2
Expand All @@ -26,6 +30,11 @@ jobs:
env:
CGO_ENABLED: 1

- uses: actions/upload-artifact@v4
with:
name: cli-${{ matrix.os }}
path: ficsit-cli

lint:
name: Lint
runs-on: ubuntu-latest
Expand Down
10 changes: 6 additions & 4 deletions cli/cache/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ func DownloadOrCache(cacheKey string, hash string, url string, updates chan<- ut
}
})

_, _ = downloadSync.Compute(cacheKey, func(oldValue *downloadGroup, loaded bool) (*downloadGroup, bool) {
oldValue.updates = append(oldValue.updates, updates)
return oldValue, false
})
if updates != nil {
_, _ = downloadSync.Compute(cacheKey, func(oldValue *downloadGroup, loaded bool) (*downloadGroup, bool) {
oldValue.updates = append(oldValue.updates, updates)
return oldValue, false
})
}

downloadCache := filepath.Join(viper.GetString("cache-dir"), "downloadCache")
if err := os.MkdirAll(downloadCache, 0o777); err != nil {
Expand Down
24 changes: 21 additions & 3 deletions cmd/apply.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"log/slog"
"os"
"sync"

"github.com/spf13/cobra"

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

var wg sync.WaitGroup
errored := false
for _, installation := range global.Installations.Installations {
if len(args) > 0 {
found := false
Expand All @@ -31,9 +37,21 @@ var applyCmd = &cobra.Command{
}
}

if err := installation.Install(global, nil); err != nil {
return err
}
wg.Add(1)

go func(installation *cli.Installation) {
defer wg.Done()
if err := installation.Install(global, nil); err != nil {
errored = true
slog.Error("installation failed", slog.Any("err", err))
}
}(installation)
}

wg.Wait()

if errored {
os.Exit(1)
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Execute(version string, commit string) {
cobra.MousetrapHelpText = ""

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

if err := RootCmd.Execute(); err != nil {
panic(err)
slog.Error(err.Error())
os.Exit(1)
}
}

Expand Down

0 comments on commit baacde4

Please sign in to comment.