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:
parent
25f544b8fe
commit
baacde400e
4 changed files with 40 additions and 10 deletions
11
.github/workflows/push.yaml
vendored
11
.github/workflows/push.yaml
vendored
|
@ -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
|
||||
|
@ -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
|
||||
|
|
2
cli/cache/download.go
vendored
2
cli/cache/download.go
vendored
|
@ -34,10 +34,12 @@ func DownloadOrCache(cacheKey string, hash string, url string, updates chan<- ut
|
|||
}
|
||||
})
|
||||
|
||||
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 {
|
||||
|
|
20
cmd/apply.go
20
cmd/apply.go
|
@ -1,6 +1,10 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/satisfactorymodding/ficsit-cli/cli"
|
||||
|
@ -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
|
||||
|
@ -31,9 +37,21 @@ var applyCmd = &cobra.Command{
|
|||
}
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func(installation *cli.Installation) {
|
||||
defer wg.Done()
|
||||
if err := installation.Install(global, nil); err != nil {
|
||||
return err
|
||||
errored = true
|
||||
slog.Error("installation failed", slog.Any("err", err))
|
||||
}
|
||||
}(installation)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if errored {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue