main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. func configure() *staticmd.Generator {
  11. // get current directory
  12. cwd, _ := os.Getwd()
  13. // prepare staticmd with dependencies & defaults
  14. smd := &staticmd.Generator{
  15. Logger: &log.Logger{},
  16. Input: cwd,
  17. Output: filepath.Join(cwd, "public/"),
  18. }
  19. // prepare cli options
  20. appOptions := option.App{Description: "command line tool for generating deliverable static content"}
  21. appOptions.Flag("template", "path to the template file", "--template", "-t")
  22. appOptions.Flag("input", "path to the markdown files", "--input", "-i")
  23. appOptions.Flag("output", "path to place generated content", "--output", "-o")
  24. appOptions.Flag("book", "combine all content into a single file", "--book", "-b")
  25. appOptions.Flag("relative", "use relative paths instead of absolute paths", "--relative", "-r")
  26. appOptions.Example("-t template.tmpl -i . -b")
  27. appOptions.Example("-t template.tmpl -i src/ -o out/ -r")
  28. flags := appOptions.Parse()
  29. // apply flags
  30. smd.TemplateFile, _ = maps.String(flags, smd.TemplateFile, "template")
  31. smd.Input, _ = maps.String(flags, smd.Input, "input")
  32. smd.Output, _ = maps.String(flags, smd.Output, "output")
  33. smd.Book, _ = maps.Bool(flags, smd.Book, "book")
  34. smd.Relative, _ = maps.Bool(flags, smd.Relative, "relative")
  35. return smd
  36. }
  37. func main() {
  38. smd := configure()
  39. if err := smd.Generate(); err != nil {
  40. smd.Logger.Error("%s", err)
  41. os.Exit(1)
  42. }
  43. }