main.go 1.2 KB

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