Skip to content

Commit c798e20

Browse files
committed
fix: Show schedule commands in help, improve template
1 parent 92ebdae commit c798e20

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cli/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,18 @@ func usageTemplate() string {
331331
{{.Example}}
332332
{{end}}
333333
334+
{{- $isRootHelp := (not .HasParent)}}
334335
{{- if .HasAvailableSubCommands}}
335336
{{usageHeader "Commands:"}}
336337
{{- range .Commands}}
337-
{{- if (or (and .IsAvailableCommand (eq (len .Annotations) 0)) (eq .Name "help"))}}
338+
{{- $hasRootAnnotations := (and $isRootHelp (eq (len .Annotations) 0))}}
339+
{{- if (or (and .IsAvailableCommand (not $hasRootAnnotations)) (eq .Name "help"))}}
338340
{{rpad .Name .NamePadding }} {{.Short}}
339341
{{- end}}
340342
{{- end}}
341343
{{end}}
342344
343-
{{- if and (not .HasParent) .HasAvailableSubCommands}}
345+
{{- if (and $isRootHelp .HasAvailableSubCommands)}}
344346
{{usageHeader "Workspace Commands:"}}
345347
{{- range .Commands}}
346348
{{- if (and .IsAvailableCommand (ne (index .Annotations "workspaces") ""))}}

cli/schedule.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,22 @@ func schedules() *cobra.Command {
6767
Long: scheduleDescriptionLong,
6868
}
6969

70-
scheduleCmd.AddCommand(scheduleShow())
71-
scheduleCmd.AddCommand(scheduleStart())
72-
scheduleCmd.AddCommand(scheduleStop())
73-
scheduleCmd.AddCommand(scheduleOverride())
70+
scheduleCmd.AddCommand(
71+
scheduleShow(),
72+
scheduleStart(),
73+
scheduleStop(),
74+
scheduleOverride(),
75+
)
7476

7577
return scheduleCmd
7678
}
7779

7880
func scheduleShow() *cobra.Command {
7981
showCmd := &cobra.Command{
80-
Annotations: workspaceCommand,
81-
Use: "show <workspace-name>",
82-
Short: "Show workspace schedule",
83-
Long: scheduleShowDescriptionLong,
84-
Args: cobra.ExactArgs(1),
82+
Use: "show <workspace-name>",
83+
Short: "Show workspace schedule",
84+
Long: scheduleShowDescriptionLong,
85+
Args: cobra.ExactArgs(1),
8586
RunE: func(cmd *cobra.Command, args []string) error {
8687
client, err := createClient(cmd)
8788
if err != nil {
@@ -101,8 +102,7 @@ func scheduleShow() *cobra.Command {
101102

102103
func scheduleStart() *cobra.Command {
103104
cmd := &cobra.Command{
104-
Annotations: workspaceCommand,
105-
Use: "start <workspace-name> { <start-time> [day-of-week] [location] | manual }",
105+
Use: "start <workspace-name> { <start-time> [day-of-week] [location] | manual }",
106106
Example: formatExamples(
107107
example{
108108
Description: "Set the workspace to start at 9:30am (in Dublin) from Monday to Friday",
@@ -153,9 +153,8 @@ func scheduleStart() *cobra.Command {
153153

154154
func scheduleStop() *cobra.Command {
155155
return &cobra.Command{
156-
Annotations: workspaceCommand,
157-
Args: cobra.ExactArgs(2),
158-
Use: "stop <workspace-name> { <duration> | manual }",
156+
Args: cobra.ExactArgs(2),
157+
Use: "stop <workspace-name> { <duration> | manual }",
159158
Example: formatExamples(
160159
example{
161160
Command: "coder schedule stop my-workspace 2h30m",
@@ -200,9 +199,8 @@ func scheduleStop() *cobra.Command {
200199

201200
func scheduleOverride() *cobra.Command {
202201
overrideCmd := &cobra.Command{
203-
Args: cobra.ExactArgs(2),
204-
Annotations: workspaceCommand,
205-
Use: "override-stop <workspace-name> <duration from now>",
202+
Args: cobra.ExactArgs(2),
203+
Use: "override-stop <workspace-name> <duration from now>",
206204
Example: formatExamples(
207205
example{
208206
Command: "coder schedule override-stop my-workspace 90m",

0 commit comments

Comments
 (0)