main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/cdelorme/go-log"
  6. "github.com/cdelorme/gonf"
  7. "github.com/cdelorme/staticmd"
  8. )
  9. var exit = os.Exit
  10. var getwd = os.Getwd
  11. type generator interface {
  12. Generate() error
  13. }
  14. func configure() generator {
  15. cwd, _ := getwd()
  16. smd := &staticmd.Generator{
  17. Logger: &log.Logger{},
  18. Input: cwd,
  19. Output: filepath.Join(cwd, "public/"),
  20. }
  21. g := &gonf.Gonf{Description: "command line tool for generating deliverable static content", Configuration: smd}
  22. g.Add("template", "path to the template file", "STATICMD_TEMPLATE", "--template", "-t")
  23. g.Add("input", "path to the markdown files", "STATICMD_INPUT", "--input", "-i")
  24. g.Add("output", "path to place generated content", "STATICMD_OUTPUT", "--output", "-o")
  25. g.Add("book", "combine all content into a single file", "STATICMD_BOOK", "--book", "-b")
  26. g.Add("relative", "use relative paths instead of absolute paths", "STATICMD_RELATIVE", "--relative", "-r")
  27. g.Example("-t template.tmpl -i . -b")
  28. g.Example("-t template.tmpl -i src/ -o out/ -r")
  29. g.Load()
  30. return smd
  31. }
  32. func main() {
  33. smd := configure()
  34. if err := smd.Generate(); err != nil {
  35. exit(1)
  36. }
  37. }