File: md2man.go

package info (click to toggle)
go-md2man 1.0.8+ds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 132 kB
  • sloc: sh: 18; makefile: 10
file content (51 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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() // nolint: errcheck

	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() // nolint: errcheck
	}
	_, err = outFile.Write(out)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}