-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
90 lines (77 loc) · 2.48 KB
/
commands.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"errors"
"fmt"
"os"
log "github.com/sirupsen/logrus"
mango "github.com/muesli/mango-cobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
gom "github.com/toolsascode/gomodeler/pkg/template"
)
var rootCmd = &cobra.Command{
Use: "gomodeler",
Version: getVersion(),
Short: "Go Modeler is a small CLI that brings the powerful features of the golang template into a simplified form.",
Long: `GoModeler brings with it all the features that gotemplate provides in a less complex and easy to implement way, including extra features.
Complete documentation is available at https://github.com/toolsascode/gomodeler`,
Run: func(_ *cobra.Command, _ []string) {
gom.RunRender()
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Go Modeler",
Long: `All software has versions. This is Go Modeler's`,
DisableFlagParsing: true,
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("Version\t:", version)
fmt.Println("Date\t:", date)
fmt.Println("Commit\t: ", commit)
fmt.Println("Built by: ", builtBy)
},
}
var docsCmd = &cobra.Command{
Use: "docs",
Short: "Generating Go Modeler CLI markdown documentation.",
Long: `Allow generating documentation in markdown format for Go Modeler CLI internal commands`,
Hidden: true,
DisableFlagParsing: true,
SilenceUsage: true,
DisableFlagsInUseLine: true,
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
Run: func(_ *cobra.Command, _ []string) {
var path = "./docs"
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(path, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
log.Info("Generating markdown documentation")
err := doc.GenMarkdownTree(rootCmd, path)
if err != nil {
log.Fatal(err)
}
log.Infof("Documentation successfully generated in %s", path)
},
}
var manCmd = &cobra.Command{
Use: "man",
Short: "Generates manpages",
DisableFlagParsing: true,
SilenceUsage: true,
DisableFlagsInUseLine: true,
Hidden: true,
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
manPage, err := mango.NewManPage(1, rootCmd.Root())
if err != nil {
return err
}
_, err = fmt.Fprint(os.Stdout, manPage.Build(roff.NewDocument()))
return err
},
}