docsonnet/main.go

45 lines
852 B
Go
Raw Normal View History

2020-03-22 16:47:47 +01:00
package main
import (
2020-04-29 16:39:37 +02:00
"fmt"
2020-03-22 16:47:47 +01:00
"io/ioutil"
"log"
2020-04-30 00:47:43 +02:00
"path/filepath"
2020-04-29 17:13:38 +02:00
"github.com/go-clix/cli"
2020-03-22 16:47:47 +01:00
2020-04-30 00:47:43 +02:00
"github.com/sh0rez/docsonnet/pkg/docsonnet"
"github.com/sh0rez/docsonnet/pkg/render"
)
2020-03-22 16:47:47 +01:00
func main() {
2020-04-30 00:47:43 +02:00
log.SetFlags(0)
2020-04-29 17:13:38 +02:00
root := &cli.Command{
Use: "docsonnet",
Short: "Utility to parse and transform Jsonnet code that uses the docsonnet extension",
}
2020-05-02 19:54:34 +02:00
output := root.Flags().StringP("output", "o", "docs", "directory to write the .md files to")
root.Run = func(cmd *cli.Command, args []string) error {
2020-04-30 00:47:43 +02:00
pkg, err := docsonnet.Load(args[0])
2020-04-29 17:13:38 +02:00
if err != nil {
return err
}
2020-05-02 19:54:34 +02:00
data := render.Render(*pkg)
for k, v := range data {
fmt.Println(k)
if err := ioutil.WriteFile(filepath.Join(*output, k), []byte(v), 0644); err != nil {
2020-04-30 00:47:43 +02:00
return err
}
2020-03-22 16:47:47 +01:00
}
2020-04-30 00:47:43 +02:00
return nil
2020-03-22 16:47:47 +01:00
}
2020-05-02 19:54:34 +02:00
if err := root.Execute(); err != nil {
log.Fatalln(err)
}
2020-03-22 16:47:47 +01:00
}