@@ -17,8 +17,10 @@ import (
17
17
"golang.org/x/crypto/ssh/terminal"
18
18
"golang.org/x/xerrors"
19
19
20
+ "github.com/coder/coder/v2/buildinfo"
20
21
"github.com/coder/coder/v2/cli/clibase"
21
22
"github.com/coder/coder/v2/cli/cliui"
23
+ "github.com/coder/pretty"
22
24
)
23
25
24
26
//go:embed help.tpl
@@ -47,12 +49,28 @@ func wrapTTY(s string) string {
47
49
var usageTemplate = template .Must (
48
50
template .New ("usage" ).Funcs (
49
51
template.FuncMap {
52
+ "version" : func () string {
53
+ return buildinfo .Version ()
54
+ },
50
55
"wrapTTY" : func (s string ) string {
51
56
return wrapTTY (s )
52
57
},
53
58
"trimNewline" : func (s string ) string {
54
59
return strings .TrimSuffix (s , "\n " )
55
60
},
61
+ "keyword" : func (s string ) string {
62
+ return pretty .Sprint (
63
+ pretty .FgColor (cliui .Color ("#0173ff" )),
64
+ s ,
65
+ )
66
+ },
67
+ "prettyHeader" : func (s string ) string {
68
+ return pretty .Sprint (
69
+ pretty .FgColor (
70
+ cliui .Color ("#ffb500" ),
71
+ ), strings .ToUpper (s ), ":" ,
72
+ )
73
+ },
56
74
"typeHelper" : func (opt * clibase.Option ) string {
57
75
switch v := opt .Value .(type ) {
58
76
case * clibase.Enum :
@@ -71,13 +89,15 @@ var usageTemplate = template.Must(
71
89
72
90
body = wordwrap .WrapString (body , uint (twidth - len (spacing )))
73
91
92
+ sc := bufio .NewScanner (strings .NewReader (body ))
93
+
74
94
var sb strings.Builder
75
- for _ , line := range strings . Split ( body , " \n " ) {
95
+ for sc . Scan ( ) {
76
96
// Remove existing indent, if any.
77
- line = strings .TrimSpace (line )
97
+ // line = strings.TrimSpace(line)
78
98
// Use spaces so we can easily calculate wrapping.
79
99
_ , _ = sb .WriteString (spacing )
80
- _ , _ = sb .WriteString ( line )
100
+ _ , _ = sb .Write ( sc . Bytes () )
81
101
_ , _ = sb .WriteString ("\n " )
82
102
}
83
103
return sb .String ()
@@ -126,9 +146,7 @@ var usageTemplate = template.Must(
126
146
"flagName" : func (opt clibase.Option ) string {
127
147
return opt .Flag
128
148
},
129
- "prettyHeader" : func (s string ) string {
130
- return cliui .Bold (s )
131
- },
149
+
132
150
"isEnterprise" : func (opt clibase.Option ) bool {
133
151
return opt .Annotations .IsSet ("enterprise" )
134
152
},
@@ -160,12 +178,6 @@ var usageTemplate = template.Must(
160
178
}
161
179
return sb .String ()
162
180
},
163
- "formatLong" : func (long string ) string {
164
- // We intentionally don't wrap here because it would misformat
165
- // examples, where the new line would start without the prior
166
- // line's indentation.
167
- return strings .TrimSpace (long )
168
- },
169
181
"formatGroupDescription" : func (s string ) string {
170
182
s = strings .ReplaceAll (s , "\n " , "" )
171
183
s = s + "\n "
0 commit comments