ficsit-cli-flake/cmd/apply.go
Vilsol baacde400e
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
2023-12-21 00:37:18 +02:00

59 lines
1,010 B
Go

package cmd
import (
"log/slog"
"os"
"sync"
"github.com/spf13/cobra"
"github.com/satisfactorymodding/ficsit-cli/cli"
)
var applyCmd = &cobra.Command{
Use: "apply [installation] ...",
Short: "Apply profiles to all installations",
RunE: func(cmd *cobra.Command, args []string) error {
global, err := cli.InitCLI(false)
if err != nil {
return err
}
var wg sync.WaitGroup
errored := false
for _, installation := range global.Installations.Installations {
if len(args) > 0 {
found := false
for _, installPath := range args {
if installation.Path == installPath {
found = true
break
}
}
if !found {
continue
}
}
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
},
}