...

Source file src/github.com/cpuguy83/go-md2man/v2/md2man.go

Documentation: github.com/cpuguy83/go-md2man/v2

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"io/ioutil"
     7  	"os"
     8  
     9  	"github.com/cpuguy83/go-md2man/v2/md2man"
    10  )
    11  
    12  var (
    13  	inFilePath  = flag.String("in", "", "Path to file to be processed (default: stdin)")
    14  	outFilePath = flag.String("out", "", "Path to output processed file (default: stdout)")
    15  )
    16  
    17  func main() {
    18  	var err error
    19  	flag.Parse()
    20  
    21  	inFile := os.Stdin
    22  	if *inFilePath != "" {
    23  		inFile, err = os.Open(*inFilePath)
    24  		if err != nil {
    25  			fmt.Println(err)
    26  			os.Exit(1)
    27  		}
    28  	}
    29  	defer inFile.Close() // nolint: errcheck
    30  
    31  	doc, err := ioutil.ReadAll(inFile)
    32  	if err != nil {
    33  		fmt.Println(err)
    34  		os.Exit(1)
    35  	}
    36  
    37  	out := md2man.Render(doc)
    38  
    39  	outFile := os.Stdout
    40  	if *outFilePath != "" {
    41  		outFile, err = os.Create(*outFilePath)
    42  		if err != nil {
    43  			fmt.Println(err)
    44  			os.Exit(1)
    45  		}
    46  		defer outFile.Close() // nolint: errcheck
    47  	}
    48  	_, err = outFile.Write(out)
    49  	if err != nil {
    50  		fmt.Println(err)
    51  		os.Exit(1)
    52  	}
    53  }
    54  

View as plain text