diff --git a/go-md2man.1.md b/go-md2man.1.md index 1f7096a..e1ae104 100644 --- a/go-md2man.1.md +++ b/go-md2man.1.md @@ -11,6 +11,8 @@ go-md2man 1 "January 2015" go-md2man "User Manual" go-md2man converts standard markdown formatted documents into manpages. It is written purely in Go so as to reduce dependencies on 3rd party libs. + By default, the input is stdin and the output is stdout. + # Example Convert the markdown file "go-md2man.1.md" into a manpage. diff --git a/md2man.go b/md2man.go index 1dc70f4..8f6dcda 100644 --- a/md2man.go +++ b/md2man.go @@ -9,16 +9,20 @@ import ( "github.com/cpuguy83/go-md2man/md2man" ) -var inFilePath = flag.String("in", "", "Path to file to be processed") -var outFilePath = flag.String("out", "", "Path to output processed file") +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, err := os.Open(*inFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) + inFile := os.Stdin + if *inFilePath != "" { + inFile, err = os.Open(*inFilePath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } } defer inFile.Close() @@ -30,12 +34,15 @@ func main() { out := md2man.Render(doc) - outFile, err := os.Create(*outFilePath) - if err != nil { - fmt.Println(err) - os.Exit(1) + outFile := os.Stdout + if *outFilePath != "" { + outFile, err = os.Create(*outFilePath) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + defer outFile.Close() } - defer outFile.Close() _, err = outFile.Write(out) if err != nil { fmt.Println(err)