You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/cmd/cluster.go

54 lines
1.0 KiB

package cmd
import (
"bufio"
"context"
"git.jfdev.de/JonasFranzDEV/hal/hal"
"git.jfdev.de/JonasFranzDEV/hal/parser"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"os"
)
var clusterCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "cluster [config file]",
RunE: runClusterCommand,
}
func init() {
rootCommand.AddCommand(clusterCmd)
}
func runClusterCommand(cmd *cobra.Command, args []string) error {
configFile := args[0]
// Parse config
if stats, err := os.Stat(configFile); err != nil || stats.IsDir() {
return err
}
file, err := os.Open(configFile)
if err != nil {
return err
}
scanner := bufio.NewScanner(file)
config := &hal.ClusterConfig{}
if err := yaml.Unmarshal(scanner.Bytes(), config); err != nil {
return err
}
// Parse modules
modules, err := parser.GetModulesFromConfig(config, debug)
if err != nil {
return err
}
// Create the cluster
cluster, err := config.BuildCluster(modules)
if err != nil {
return err
}
// Run
return cluster.Run(context.Background())
}