Add -format flag

This commit is contained in:
adnano 2021-02-27 15:34:05 -05:00
parent 6e8f7cfdaa
commit f1d0710f95

22
main.go
View file

@ -17,11 +17,20 @@ func main() {
} }
func run() error { func run() error {
// whether or not to output HTML var format string
var toHTML bool flag.StringVar(&format, "format", "gemini", "output format to use. Supported formats include gemini and html")
flag.BoolVar(&toHTML, "html", false, "output HTML")
flag.Parse() flag.Parse()
var output outputFormat
switch format {
case "gemini":
output = outputGemini
case "html":
output = outputHTML
default:
log.Fatalf("unknown output format %q", format)
}
// Load config // Load config
cfg := NewConfig() cfg := NewConfig()
if err := cfg.Load("config.ini"); err != nil { if err := cfg.Load("config.ini"); err != nil {
@ -42,14 +51,9 @@ func run() error {
return err return err
} }
// Write content // Write content
if err := dir.write("dst", outputGemini, cfg); err != nil { if err := dir.write("dst", output, cfg); err != nil {
return err return err
} }
if toHTML {
if err := dir.write("html", outputHTML, cfg); err != nil {
return err
}
}
return nil return nil
} }