mirror of
https://github.com/TECHNOFAB11/docsonnet.git
synced 2025-12-14 07:13:55 +01:00
feat: ignore
Implements ignoring certain keys right in Jsonnet, by adding:
{
'#foo': "ignore",
foo: {}
}
This is especially useful for objects that include `self` references,
which might otherwise recurse infinitely
This commit is contained in:
parent
14e9fc8f3f
commit
66a158a8f2
7 changed files with 85 additions and 46 deletions
49
main.go
49
main.go
|
|
@ -15,33 +15,52 @@ func main() {
|
|||
log.SetFlags(0)
|
||||
|
||||
root := &cli.Command{
|
||||
Use: "docsonnet",
|
||||
Use: "docsonnet <file>",
|
||||
Short: "Utility to parse and transform Jsonnet code that uses the docsonnet extension",
|
||||
Args: cli.ArgsExact(1),
|
||||
}
|
||||
|
||||
dir := root.Flags().StringP("output", "o", "docs", "directory to write the .md files to")
|
||||
outputMd := root.Flags().Bool("md", true, "render as markdown files")
|
||||
outputJSON := root.Flags().Bool("json", false, "print loaded docsonnet as JSON")
|
||||
outputRaw := root.Flags().Bool("raw", false, "don't transform, dump raw eval result")
|
||||
urlPrefix := root.Flags().String("urlPrefix", "/", "url-prefix for frontmatter")
|
||||
|
||||
root.Run = func(cmd *cli.Command, args []string) error {
|
||||
file := args[0]
|
||||
|
||||
switch {
|
||||
case *outputJSON:
|
||||
model, err := docsonnet.Load(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := json.MarshalIndent(model, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Extracting from Jsonnet")
|
||||
data, err := docsonnet.Extract(file)
|
||||
if err != nil {
|
||||
log.Fatalln("Extracting:", err)
|
||||
}
|
||||
if *outputRaw {
|
||||
fmt.Println(string(data))
|
||||
case *outputMd:
|
||||
return render.To(file, *dir)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Println("Transforming to docsonnet model")
|
||||
pkg, err := docsonnet.Transform(data)
|
||||
if err != nil {
|
||||
log.Fatalln("Transforming:", err)
|
||||
}
|
||||
if *outputJSON {
|
||||
data, err := json.MarshalIndent(pkg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(data))
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Println("Rendering markdown")
|
||||
n, err := render.To(*pkg, *dir, render.Opts{
|
||||
URLPrefix: *urlPrefix,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalln("Rendering:", err)
|
||||
}
|
||||
|
||||
log.Printf("Success! Rendered %v packages from '%s' to '%s'", n, file, *dir)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue