ficsit-cli-flake/cmd/apply.go

60 lines
1,010 B
Go
Raw Permalink Normal View History

2022-06-08 20:56:32 +00:00
package cmd
import (
"log/slog"
"os"
"sync"
2022-06-08 20:56:32 +00:00
"github.com/spf13/cobra"
2022-10-14 16:11:16 +00:00
"github.com/satisfactorymodding/ficsit-cli/cli"
2022-06-08 20:56:32 +00:00
)
var applyCmd = &cobra.Command{
2022-06-11 01:01:51 +00:00
Use: "apply [installation] ...",
2022-06-08 20:56:32 +00:00
Short: "Apply profiles to all installations",
RunE: func(cmd *cobra.Command, args []string) error {
2022-10-14 16:11:16 +00:00
global, err := cli.InitCLI(false)
2022-06-11 01:01:51 +00:00
if err != nil {
return err
}
var wg sync.WaitGroup
errored := false
2022-06-11 01:01:51 +00:00
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)
2022-06-11 01:01:51 +00:00
}
2022-06-08 20:56:32 +00:00
return nil
},
}