2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-28 04:56:04 +00:00
restic/vendor/github.com/cpuguy83/go-md2man/md2man.go
2017-08-05 11:08:49 +02:00

52 lines
860 B
Go

package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/cpuguy83/go-md2man/md2man"
)
var inFilePath = flag.String("in", "", "Path to file to be processed (default: stdin)")
var outFilePath = flag.String("out", "", "Path to output processed file (default: stdout)")
func main() {
var err error
flag.Parse()
inFile := os.Stdin
if *inFilePath != "" {
inFile, err = os.Open(*inFilePath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
defer inFile.Close()
doc, err := ioutil.ReadAll(inFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
out := md2man.Render(doc)
outFile := os.Stdout
if *outFilePath != "" {
outFile, err = os.Create(*outFilePath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outFile.Close()
}
_, err = outFile.Write(out)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}