2017-05-11 16:39:54 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 16:51:38 +01:00
|
|
|
defer inFile.Close() // nolint: errcheck
|
2017-05-11 16:39:54 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2018-03-19 16:51:38 +01:00
|
|
|
defer outFile.Close() // nolint: errcheck
|
2017-05-11 16:39:54 +02:00
|
|
|
}
|
|
|
|
_, err = outFile.Write(out)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|