ficsit-cli-flake/cmd/installation/set-profile.go

45 lines
823 B
Go
Raw Normal View History

2022-06-08 20:56:32 +00:00
package installation
import (
"errors"
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
)
func init() {
Cmd.AddCommand(setProfileCmd)
}
var setProfileCmd = &cobra.Command{
Use: "set-profile <path> <profile>",
Short: "Change the profile of an installation",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
2022-10-14 16:11:16 +00:00
global, err := cli.InitCLI(false)
2022-06-08 20:56:32 +00:00
if err != nil {
return err
}
var installation *cli.Installation
for _, install := range global.Installations.Installations {
if install.Path == args[0] {
installation = install
break
}
}
if installation == nil {
return errors.New("installation not found")
}
err = installation.SetProfile(global, args[1])
if err != nil {
return err
}
return global.Save()
},
}