-
Notifications
You must be signed in to change notification settings - Fork 943
feat: add autostart/autostop show, show autostart/autostop schedule in ls output #1436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…n ls output
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,52 @@ func autostart() *cobra.Command { | |
Example: "coder autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin", | ||
} | ||
|
||
autostartCmd.AddCommand(autostartShow()) | ||
autostartCmd.AddCommand(autostartEnable()) | ||
autostartCmd.AddCommand(autostartDisable()) | ||
|
||
return autostartCmd | ||
} | ||
|
||
func autostartShow() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "show <workspace_name>", | ||
< 8000 span class='blob-code-inner blob-code-marker ' data-code-marker="+"> Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := createClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
organization, err := currentOrganization(cmd, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
workspace, err := client.WorkspaceByOwnerAndName(cmd.Context(), organization.ID, codersdk.Me, args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if workspace.AutostartSchedule == "" { | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "not enabled") | ||
return nil | ||
} | ||
|
||
validSchedule, err := schedule.Weekly(workspace.AutostartSchedule) | ||
if err != nil { | ||
// This should never happen. | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "invalid autostart schedule %q for workspace %s: %s", workspace.AutostartSchedule, workspace.Name, err.Error()) | ||
return nil | ||
} | ||
|
||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nschedule: %s\nnext: %s\n", workspace.AutostartSchedule, validSchedule.Next(time.Now())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any particular reason for printing an extra blank line at the beginning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably because I yanked the line from somewhere else and forgot to clean it up 🙃 |
||
|
||
return nil | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func autostartEnable() *cobra.Command { | ||
// yes some of these are technically numbers but the cron library will do that work | ||
var autostartMinute string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this and some of the other
fmt.Fprintf
calls inautostart.go
andautostop.go
are missing trailing newlines.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops!