Skip to content

Commit 49941f3

Browse files
committed
feat(cli): colorize help page
Inspired by sharkdp's tooling.
1 parent dd97fe2 commit 49941f3

File tree

86 files changed

+686
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+686
-398
lines changed

cli/cliui/cliui.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
Red = color.Color("#ED567A")
4949
Fuchsia = color.Color("#EE6FF8")
5050
Yellow = color.Color("#ECFD65")
51+
Gold = color.Color("#ffd700")
5152
Blue = color.Color("#5000ff")
5253
)
5354

cli/help.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"golang.org/x/crypto/ssh/terminal"
1818
"golang.org/x/xerrors"
1919

20+
"github.com/coder/coder/v2/buildinfo"
2021
"github.com/coder/coder/v2/cli/clibase"
2122
"github.com/coder/coder/v2/cli/cliui"
23+
"github.com/coder/pretty"
2224
)
2325

2426
//go:embed help.tpl
@@ -47,12 +49,21 @@ func wrapTTY(s string) string {
4749
var usageTemplate = template.Must(
4850
template.New("usage").Funcs(
4951
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+
},
5058
"wrapTTY": func(s string) string {
5159
return wrapTTY(s)
5260
},
5361
"trimNewline": func(s string) string {
5462
return strings.TrimSuffix(s, "\n")
5563
},
64+
"keyword": func(s string) string {
65+
return cliui.Keyword(s)
66+
},
5667
"typeHelper": func(opt *clibase.Option) string {
5768
switch v := opt.Value.(type) {
5869
case *clibase.Enum:
@@ -127,7 +138,9 @@ var usageTemplate = template.Must(
127138
return opt.Flag
128139
},
129140
"prettyHeader": func(s string) string {
130-
return cliui.Bold(s)
141+
return pretty.Sprint(
142+
pretty.FgColor(cliui.Gold), strings.ToUpper(s), ":",
143+
)
131144
},
132145
"isEnterprise": func(opt clibase.Option) bool {
133146
return opt.Annotations.IsSet("enterprise")

cli/help.tpl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
{{- /* Heavily inspired by the Go toolchain formatting. */ -}}
2-
Usage: {{.FullUsage}}
1+
{{- /* Heavily inspired by the Go toolchain and fd */ -}}
2+
{{nameVersion}}
3+
4+
{{prettyHeader "Usage"}}
5+
{{indent .FullUsage 2}}
36

47

58
{{ with .Short }}
6-
{{- wrapTTY . }}
9+
{{- indent . 2 | wrapTTY }}
710
{{"\n"}}
811
{{- end}}
912

1013
{{ with .Aliases }}
11-
{{ "\n" }}
12-
{{ "Aliases:"}} {{ joinStrings .}}
13-
{{ "\n" }}
14+
{{" Aliases: "}} {{- joinStrings .}}
1415
{{- end }}
1516

1617
{{- with .Long}}
17-
{{- formatLong . }}
18+
{{- $long := formatLong . }}
19+
{{- indent $long 2}}
1820
{{ "\n" }}
1921
{{- end }}
2022
{{ with visibleChildren . }}
@@ -34,11 +36,11 @@ Usage: {{.FullUsage}}
3436
{{- else }}
3537
{{- end }}
3638
{{- range $index, $option := $group.Options }}
37-
{{- if not (eq $option.FlagShorthand "") }}{{- print "\n -" $option.FlagShorthand ", " -}}
39+
{{- if not (eq $option.FlagShorthand "") }}{{- print "\n "}} {{ keyword "-"}}{{keyword $option.FlagShorthand }}{{", "}}
3840
{{- else }}{{- print "\n " -}}
3941
{{- end }}
40-
{{- with flagName $option }}--{{ . }}{{ end }} {{- with typeHelper $option }} {{ . }}{{ end }}
41-
{{- with envName $option }}, ${{ . }}{{ end }}
42+
{{- with flagName $option }}{{keyword "--"}}{{ keyword . }}{{ end }} {{- with typeHelper $option }} {{ . }}{{ end }}
43+
{{- with envName $option }}, {{ print "$" . | keyword }}{{ end }}
4244
{{- with $option.Default }} (default: {{ . }}){{ end }}
4345
{{- with $option.Description }}
4446
{{- $desc := $option.Description }}

cli/testdata/coder_--help.golden

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
Usage: coder [global-flags] <subcommand>
1+
coder v0.0.0-devel
22

3-
Coder v0.0.0-devel — A tool for provisioning self-hosted development environments with Terraform.
4-
- Start a Coder server:
5-
6-
$ coder server
3+
USAGE:
4+
coder [global-flags] <subcommand>
75

6+
Coder v0.0.0-devel — A tool for provisioning self-hosted development
7+
environments with Terraform.
8+
- Start a Coder server:
9+
10+
$ coder server
11+
812
- Get started by creating a template from an example:
13+
14+
$ coder templates init
915

10-
$ coder templates init
11-
12-
Subcommands
16+
SUBCOMMANDS:
1317
config-ssh Add an SSH Host entry for your workspaces "ssh
1418
coder.workspace"
1519
create Create a workspace
@@ -45,7 +49,7 @@ Coder v0.0.0-devel — A tool for provisioning self-hosted development environme
4549
users Manage users
4650
version Show coder version
4751

48-
Global Options
52+
GLOBAL OPTIONS:
4953
Global options are applied to all commands. They can be set using environment
5054
variables or flags.
5155

cli/testdata/coder_agent_--help.golden

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
Usage: coder agent [flags]
1+
coder v0.0.0-devel
22

3-
Starts the Coder workspace agent.
3+
USAGE:
4+
coder agent [flags]
45

5-
Options
6+
Starts the Coder workspace agent.
7+
8+
OPTIONS:
69
--log-human string, $CODER_AGENT_LOGGING_HUMAN (default: /dev/stderr)
710
Output human-readable logs to a given file.
811

cli/testdata/coder_config-ssh_--help.golden

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
Usage: coder config-ssh [flags]
1+
coder v0.0.0-devel
22

3-
Add an SSH Host entry for your workspaces "ssh coder.workspace"
3+
USAGE:
4+
coder config-ssh [flags]
45

5-
- You can use -o (or --ssh-option) so set SSH options to be used for all your
6-
workspaces:
7-
8-
$ coder config-ssh -o ForwardAgent=yes
6+
Add an SSH Host entry for your workspaces "ssh coder.workspace"
97

8+
- You can use -o (or --ssh-option) so set SSH options to be used for all your
9+
workspaces:
10+
11+
$ coder config-ssh -o ForwardAgent=yes
12+
1013
- You can use --dry-run (or -n) to see the changes that would be made:
14+
15+
$ coder config-ssh --dry-run
1116

12-
$ coder config-ssh --dry-run
13-
14-
Options
17+
OPTIONS:
1518
--coder-binary-path string, $CODER_SSH_CONFIG_BINARY_PATH
1619
Optionally specify the absolute path to the coder binary used in
1720
ProxyCommand. By default, the binary invoking this command ('config

cli/testdata/coder_create_--help.golden

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
Usage: coder create [flags] [name]
1+
coder v0.0.0-devel
22

3-
Create a workspace
3+
USAGE:
4+
coder create [flags] [name]
45

5-
- Create a workspace for another user (if you have permission):
6+
Create a workspace
67

7-
$ coder create <username>/<workspace_name>
8+
- Create a workspace for another user (if you have permission):
9+
10+
$ coder create <username>/<workspace_name>
811

9-
Options
12+
OPTIONS:
1013
--parameter string-array, $CODER_RICH_PARAMETER
1114
Rich parameter value in the format "name=value".
1215

cli/testdata/coder_delete_--help.golden

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
Usage: coder delete [flags] <workspace>
1+
coder v0.0.0-devel
22

3-
Delete a workspace
3+
USAGE:
4+
coder delete [flags] <workspace>
45

5-
Aliases: rm
6+
Delete a workspace
67

7-
Options
8+
Aliases: rm
9+
10+
OPTIONS:
811
--orphan bool
912
Delete a workspace without deleting its resources. This can delete a
1013
workspace in a broken state, but may also lead to unaccounted cloud

cli/testdata/coder_dotfiles_--help.golden

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
Usage: coder dotfiles [flags] <git_repo_url>
1+
coder v0.0.0-devel
22

3-
Personalize your workspace by applying a canonical dotfiles repository
3+
USAGE:
4+
coder dotfiles [flags] <git_repo_url>
45

5-
- Check out and install a dotfiles repository without prompts:
6+
Personalize your workspace by applying a canonical dotfiles repository
67

7-
$ coder dotfiles --yes git@github.com:example/dotfiles.git
8+
- Check out and install a dotfiles repository without prompts:
9+
10+
$ coder dotfiles --yes git@github.com:example/dotfiles.git
811

9-
Options
12+
OPTIONS:
1013
-b, --branch string
1114
Specifies which branch to clone. If empty, will default to cloning the
1215
default branch or using the existing branch in the cloned repo on

cli/testdata/coder_list_--help.golden

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
Usage: coder list [flags]
1+
coder v0.0.0-devel
22

3-
List workspaces
3+
USAGE:
4+
coder list [flags]
45

5-
Aliases: ls
6+
List workspaces
67

7-
Options
8+
Aliases: ls
9+
10+
OPTIONS:
811
-a, --all bool
912
Specifies whether all workspaces will be listed or not.
1013

0 commit comments

Comments
 (0)