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
This commit is contained in:
Vilsol 2023-12-20 14:37:18 -08:00 committed by GitHub
parent 25f544b8fe
commit baacde400e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 10 deletions

View file

@ -5,7 +5,11 @@ on: [push, pull_request]
jobs: jobs:
build: build:
name: Build name: Build
runs-on: ubuntu-latest strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps: steps:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
@ -26,6 +30,11 @@ jobs:
env: env:
CGO_ENABLED: 1 CGO_ENABLED: 1
- uses: actions/upload-artifact@v4
with:
name: cli-${{ matrix.os }}
path: ficsit-cli
lint: lint:
name: Lint name: Lint
runs-on: ubuntu-latest runs-on: ubuntu-latest

10
cli/cache/download.go vendored
View file

@ -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) { if updates != nil {
oldValue.updates = append(oldValue.updates, updates) _, _ = downloadSync.Compute(cacheKey, func(oldValue *downloadGroup, loaded bool) (*downloadGroup, bool) {
return oldValue, false oldValue.updates = append(oldValue.updates, updates)
}) return oldValue, false
})
}
downloadCache := filepath.Join(viper.GetString("cache-dir"), "downloadCache") downloadCache := filepath.Join(viper.GetString("cache-dir"), "downloadCache")
if err := os.MkdirAll(downloadCache, 0o777); err != nil { if err := os.MkdirAll(downloadCache, 0o777); err != nil {

View file

@ -1,6 +1,10 @@
package cmd package cmd
import ( import (
"log/slog"
"os"
"sync"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/satisfactorymodding/ficsit-cli/cli" "github.com/satisfactorymodding/ficsit-cli/cli"
@ -15,6 +19,8 @@ var applyCmd = &cobra.Command{
return err return err
} }
var wg sync.WaitGroup
errored := false
for _, installation := range global.Installations.Installations { for _, installation := range global.Installations.Installations {
if len(args) > 0 { if len(args) > 0 {
found := false found := false
@ -31,9 +37,21 @@ var applyCmd = &cobra.Command{
} }
} }
if err := installation.Install(global, nil); err != nil { wg.Add(1)
return err
} 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 return nil

View file

@ -94,7 +94,7 @@ func Execute(version string, commit string) {
cobra.MousetrapHelpText = "" cobra.MousetrapHelpText = ""
cli := len(os.Args) >= 2 && os.Args[1] == "cli" 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:]...) args := append([]string{"cli"}, os.Args[1:]...)
RootCmd.SetArgs(args) RootCmd.SetArgs(args)
cli = true cli = true
@ -109,7 +109,8 @@ func Execute(version string, commit string) {
viper.Set("commit", commit) viper.Set("commit", commit)
if err := RootCmd.Execute(); err != nil { if err := RootCmd.Execute(); err != nil {
panic(err) slog.Error(err.Error())
os.Exit(1)
} }
} }