package main

import (
	"flag"
	"fmt"
	"os"

	"github.com/ultisuite/ulti-backend/internal/envexpand"
)

func main() {
	in := flag.String("in", ".env", "input .env file")
	out := flag.String("out", "", "output file (default: stdout)")
	flag.Parse()

	if err := run(*in, *out); err != nil {
		fmt.Fprintf(os.Stderr, "envexpand: %v\n", err)
		os.Exit(1)
	}
}

func run(inPath, outPath string) error {
	if outPath == "" {
		return envexpand.RenderToWriter(inPath, os.Stdout)
	}
	return envexpand.Render(inPath, outPath)
}
