-
-
Notifications
You must be signed in to change notification settings - Fork 140
/
info.go
118 lines (91 loc) · 2.2 KB
/
info.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"os"
"github.com/olekukonko/tablewriter"
"github.com/pterm/pterm"
"github.com/spf13/pflag"
"github.com/errata-ai/vale/v3/internal/core"
)
var exampleConfig = `MinAlertLevel = suggestion
[*]
BasedOnStyles = Vale`
var intro = fmt.Sprintf(`vale - A command-line linter for prose.
%s: %s
%s
%s
Vale is a syntax-aware linter for prose built with speed and extensibility in
mind. It supports Markdown, AsciiDoc, reStructuredText, HTML, and more.
To get started, you'll need a configuration file (%s):
%s:
%s
See %s for more setup information.`,
pterm.Bold.Sprintf("Usage"),
toCodeStyle("vale [options] [input...]"),
toCodeStyle("vale myfile.md myfile1.md mydir1"),
toCodeStyle("vale --output=JSON [input...]"),
toCodeStyle(".vale.ini"),
pterm.Bold.Sprintf("Example"),
toCodeStyle(exampleConfig),
pterm.Underscore.Sprintf("https://vale.sh"))
var info = fmt.Sprintf(`%s
(Or use %s for a listing of all CLI options.)`,
intro,
toCodeStyle("vale --help"))
var hidden = []string{
"mode-compat",
"mode-rev-compat",
"normalize",
"relative",
"sort",
"sources",
"built",
"minAlertLevel",
// API stuff
"tag",
"compile",
"run",
"fix",
"verify",
"transform",
"ls-path",
"host-install",
"host-uninstall",
}
// PrintIntro shows basic usage / getting started info.
func PrintIntro() {
fmt.Println(info)
os.Exit(0)
}
func toFlag(name string) string {
if code, ok := shortcodes[name]; ok {
return fmt.Sprintf("%s, %s", toCodeStyle("-"+code), toCodeStyle("--"+name))
}
return toCodeStyle("--" + name)
}
func init() {
pflag.Usage = func() {
fmt.Println(intro)
table := tablewriter.NewWriter(os.Stdout)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetAutoWrapText(false)
fmt.Println(pterm.Bold.Sprintf("\nFlags:"))
pflag.VisitAll(func(f *pflag.Flag) {
if !core.StringInSlice(f.Name, hidden) {
table.Append([]string{toFlag(f.Name), f.Usage})
}
})
table.Render()
table.ClearRows()
fmt.Println(pterm.Bold.Sprintf("Commands:"))
for cmd, use := range commandInfo {
if !core.StringInSlice(cmd, hidden) {
table.Append([]string{toCodeStyle(cmd), use})
}
}
table.Render()
os.Exit(0)
}
}