-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (51 loc) · 1.23 KB
/
main.go
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
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
// Version represents the version.
Version = "dev"
// Revision set "git rev-parse --short HEAD".
Revision = "HEAD"
)
var only bool
func main() {
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "mdviewer fileName.md",
Short: "markdown viewer",
Version: fmt.Sprintf("%s (rev: %s)", Version, Revision),
Long: `markdown viewer.
Render and display markdown on the terminal`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
return
}
mdViewer, err := MDViewer(only, args)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err = mdViewer.Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func init() {
cobra.OnInitialize()
rootCmd.PersistentFlags().BoolVarP(&only, "only", "o", false, "markdown render only")
}