// Copyright 2024 Matthew Rich . All rights reserved. package main import ( "os" "flag" "log" "log/slog" _ "fmt" _ "gopkg.in/yaml.v3" "decl/internal/resource" ) func main() { var programLevel = new(slog.LevelVar) logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: programLevel})) slog.SetDefault(logger) if debugLogging,ok := os.LookupEnv("DECL_DEBUG"); ok && debugLogging != "" { programLevel.Set(slog.LevelDebug) } else { programLevel.Set(slog.LevelError) } file := flag.String("resource-file", "", "Resource file path") resourceUri := flag.String("import-resource", "", "Add an existing resource") flag.Parse() var resourceFile *os.File var inputFileErr error if *file != "" { resourceFile,inputFileErr = os.Open(*file) } else { if stdinInfo, stdinErr := os.Stdin.Stat(); stdinErr == nil { if (stdinInfo.Mode() & os.ModeCharDevice) == 0 { resourceFile = os.Stdin } } else { return } } if inputFileErr != nil { log.Fatal(inputFileErr) } d := resource.NewDocument() if e := d.Load(resourceFile); e != nil { log.Fatal(e) } if applyErr := d.Apply(); applyErr != nil { log.Fatal(applyErr) } if *resourceUri != "" { d.AddResource(*resourceUri) } d.Generate(os.Stdout) }