package main

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

	"metis/pkg/facts"
	"metis/pkg/inventory"
)

func factsCmd(args []string) {
	fs := flag.NewFlagSet("facts", flag.ExitOnError)
	invPath := fs.String("inventory", "inventory.yaml", "inventory file")
	dir := fs.String("snapshots", "snapshots", "directory of sentinel snapshot json files")
	fs.Parse(args)
	inv, err := inventory.Load(*invPath)
	if err != nil {
		fatalf("load inventory: %v", err)
	}
	snaps, err := facts.LoadDir(*dir)
	if err != nil {
		fatalf("load snapshots: %v", err)
	}
	sum := facts.Aggregate(inv, snaps)
	enc := json.NewEncoder(os.Stdout)
	enc.SetIndent("", "  ")
	if err := enc.Encode(sum); err != nil {
		fmt.Fprintf(os.Stderr, "encode: %v\n", err)
	}
}
