parent
5efab86f1a
commit
ff409401c3
@ -0,0 +1,54 @@ |
|||||||
|
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()) |
||||||
|
} |
Loading…
Reference in new issue