diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml index aacc8a5..8b64f20 100644 --- a/.github/workflows/push.yaml +++ b/.github/workflows/push.yaml @@ -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 diff --git a/cli/cache/download.go b/cli/cache/download.go index 33c7317..3f5a717 100644 --- a/cli/cache/download.go +++ b/cli/cache/download.go @@ -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 { diff --git a/cmd/apply.go b/cmd/apply.go index bbbe3f9..e99b95e 100644 --- a/cmd/apply.go +++ b/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{ } } - 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 diff --git a/cmd/root.go b/cmd/root.go index f3b37a7..6c4369f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) } }