fix: cli: prettify schedule when printing output (#1440)

* Adds methods to schedule.Schedule to show the raw cron string and timezone
* Uses these methods to clean up output of auto(start|stop) show or ls
* Defaults CRON_TZ=UTC if not provided
This commit is contained in:
Cian Johnston
2022-05-16 17:02:44 +01:00
committed by GitHub
parent 2a278b8698
commit b7049032a0
7 changed files with 77 additions and 16 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/autobuild/schedule"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
)
@ -108,14 +109,18 @@ func list() *cobra.Command {
durationDisplay = durationDisplay[:len(durationDisplay)-2]
}
autostartDisplay := "not enabled"
autostartDisplay := "-"
if workspace.AutostartSchedule != "" {
autostartDisplay = workspace.AutostartSchedule
if sched, err := schedule.Weekly(workspace.AutostartSchedule); err == nil {
autostartDisplay = sched.Cron()
}
}
autostopDisplay := "not enabled"
autostopDisplay := "-"
if workspace.AutostopSchedule != "" {
autostopDisplay = workspace.AutostopSchedule
if sched, err := schedule.Weekly(workspace.AutostopSchedule); err == nil {
autostopDisplay = sched.Cron()
}
}
user := usersByID[workspace.OwnerID]