main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. smd.TemplateFile, _ = maps.String(flags, smd.TemplateFile, "template")
  32. smd.Input, _ = maps.String(flags, smd.Input, "input")
  33. smd.Output, _ = maps.String(flags, smd.Output, "output")
  34. smd.Book, _ = maps.Bool(flags, smd.Book, "book")
  35. smd.Relative, _ = maps.Bool(flags, smd.Relative, "relative")
  36. return smd
  37. }
  38. func main() {
  39. smd := configure()
  40. if err := smd.Generate(); err != nil {
  41. exit(1)
  42. }
  43. }