54 lines
1018 B
Go
54 lines
1018 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"flag"
|
|
"log"
|
|
_ "fmt"
|
|
_ "gopkg.in/yaml.v3"
|
|
"decl/internal/resource"
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
|
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)
|
|
}
|