@@ -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,21 @@ func wrapTTY(s string) string {
47
49
var usageTemplate = template .Must (
48
50
template .New ("usage" ).Funcs (
49
51
template.FuncMap {
52
+ "nameVersion" : func () string {
53
+ txt := pretty .String ("coder" )
54
+ pretty .FgColor (cliui .Green ).Format (txt )
55
+ txt .Append (" " , buildinfo .Version ())
56
+ return txt .String ()
57
+ },
50
58
"wrapTTY" : func (s string ) string {
51
59
return wrapTTY (s )
52
60
},
53
61
"trimNewline" : func (s string ) string {
54
62
return strings .TrimSuffix (s , "\n " )
55
63
},
64
+ "keyword" : func (s string ) string {
65
+ return cliui .Keyword (s )
66
+ },
56
67
"typeHelper" : func (opt * clibase.Option ) string {
57
68
switch v := opt .Value .(type ) {
58
69
case * clibase.Enum :
@@ -71,13 +82,15 @@ var usageTemplate = template.Must(
71
82
72
83
body = wordwrap .WrapString (body , uint (twidth - len (spacing )))
73
84
85
+ sc := bufio .NewScanner (strings .NewReader (body ))
86
+
74
87
var sb strings.Builder
75
- for _ , line := range strings . Split ( body , " \n " ) {
88
+ for sc . Scan ( ) {
76
89
// Remove existing indent, if any.
77
- line = strings .TrimSpace (line )
90
+ // line = strings.TrimSpace(line)
78
91
// Use spaces so we can easily calculate wrapping.
79
92
_ , _ = sb .WriteString (spacing )
80
- _ , _ = sb .WriteString ( line )
93
+ _ , _ = sb .Write ( sc . Bytes () )
81
94
_ , _ = sb .WriteString ("\n " )
82
95
}
83
96
return sb .String ()
@@ -127,7 +140,9 @@ var usageTemplate = template.Must(
127
140
return opt .Flag
128
141
},
129
142
"prettyHeader" : func (s string ) string {
130
- return cliui .Bold (s )
143
+ return pretty .Sprint (
144
+ pretty .FgColor (cliui .Gold ), strings .ToUpper (s ), ":" ,
145
+ )
131
146
},
132
147
"isEnterprise" : func (opt clibase.Option ) bool {
133
148
return opt .Annotations .IsSet ("enterprise" )
0 commit comments