package main

import (
	"encoding/json"
	"flag"
	"os"

	"metis/pkg/config"
)

func configCmd(args []string) {
	fs := flag.NewFlagSet("config", flag.ExitOnError)
	invPath := fs.String("inventory", "inventory.yaml", "inventory file")
	node := fs.String("node", "", "target node")
	fs.Parse(args)
	if *node == "" {
		fatalf("--node is required")
	}
	inv := loadInventory(*invPath)
	cfg, err := config.Build(inv, *node)
	if err != nil {
		fatalf("config build: %v", err)
	}
	enc := json.NewEncoder(os.Stdout)
	enc.SetIndent("", "  ")
	_ = enc.Encode(cfg)
}
