diff options
Diffstat (limited to 'tools/sw-convert')
-rw-r--r-- | tools/sw-convert/main.go | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/tools/sw-convert/main.go b/tools/sw-convert/main.go index 77a459c..fb6da47 100644 --- a/tools/sw-convert/main.go +++ b/tools/sw-convert/main.go @@ -10,8 +10,8 @@ import ( "tildegit.org/tjp/sliderule/gemini/gemtext/atomconv" gem_htmlconv "tildegit.org/tjp/sliderule/gemini/gemtext/htmlconv" gem_mdconv "tildegit.org/tjp/sliderule/gemini/gemtext/mdconv" - goph_htmlconv "tildegit.org/tjp/sliderule/gopher/gophermap/htmlconv" "tildegit.org/tjp/sliderule/gopher/gophermap" + goph_htmlconv "tildegit.org/tjp/sliderule/gopher/gophermap/htmlconv" goph_mdconv "tildegit.org/tjp/sliderule/gopher/gophermap/mdconv" ) @@ -89,55 +89,58 @@ func main() { fail("template loading failed") } - switch conf.input + "-" + conf.output { - case "gemtext-markdown": - doc, err := gemtext.Parse(os.Stdin) - if err != nil { - fail("gemtext reading failed") - } - if err := gem_mdconv.Convert(os.Stdout, doc, tover); err != nil { - fail("markdown writing failed") - } - case "gemtext-html": - doc, err := gemtext.Parse(os.Stdin) - if err != nil { - fail("gemtext reading failed") - } - if err := gem_htmlconv.Convert(os.Stdout, doc, hover); err != nil { - fail("html writing failed") - } - case "gemtext-atom": - u, err := url.Parse(conf.location) - if conf.location == "" || err != nil { - fail("-l|--location must be provided and valid for gemtext to atom conversion") - } + switch conf.input { + case "gemtext": doc, err := gemtext.Parse(os.Stdin) if err != nil { - fail("gemtext reading failed") + fail("failure reading gemtext") } - if err := atomconv.Convert(os.Stdout, doc, u); err != nil { - fail("atom writing failed") - } - case "gophermap-markdown": - doc, err := gophermap.Parse(os.Stdin) - if err != nil { - fail("gophermap reading failed") - } - if err := goph_mdconv.Convert(os.Stdout, doc, tover); err != nil { - fail("markdown wriiting failed") + + switch conf.output { + case "markdown": + if err := gem_mdconv.Convert(os.Stdout, doc, tover); err != nil { + fail("failure writing markdown") + } + case "html": + if err := gem_htmlconv.Convert(os.Stdout, doc, hover); err != nil { + fail("failure writing html") + } + case "atom": + u, err := url.Parse(conf.location) + if conf.location == "" || err != nil { + fail("-l|--location must be a valid url for gemtext->atom conversion") + } + if err := atomconv.Convert(os.Stdout, doc, u); err != nil { + fail("failure writing atom XML") + } + default: + goto unknown } - case "gophermap-html": + case "gophermap": doc, err := gophermap.Parse(os.Stdin) if err != nil { - fail("gophermap reading failed") + fail("failure reading gophermap") } - if err := goph_htmlconv.Convert(os.Stdout, doc, hover); err != nil { - fail("html writing failed") + + switch conf.output { + case "markdown": + if err := goph_mdconv.Convert(os.Stdout, doc, tover); err != nil { + fail("failure writing markdown") + } + case "html": + if err := goph_htmlconv.Convert(os.Stdout, doc, hover); err != nil { + fail("failure writing html") + } + default: + goto unknown } - default: + } + + return + + unknown: os.Stderr.WriteString("unsupported input/output combination\n") fail(formats) - } } type config struct { |