Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit037b348

Browse files
committed
feat: cli: prettify autostart/autostop output
1 parent5f7cf87 commit037b348

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

‎cli/autostart.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ func autostartShow() *cobra.Command {
6363
returnnil
6464
}
6565

66-
_,_=fmt.Fprintf(cmd.OutOrStdout(),"schedule: %s\nnext: %s\n",workspace.AutostartSchedule,validSchedule.Next(time.Now()))
66+
next:=validSchedule.Next(time.Now())
67+
loc,_:=time.LoadLocation(validSchedule.Timezone())
68+
69+
_,_=fmt.Fprintf(cmd.OutOrStdout(),
70+
"schedule: %s\ntimezone: %s\nnext: %s\n",
71+
validSchedule.Cron(),
72+
validSchedule.Timezone(),
73+
next.In(loc),
74+
)
6775

6876
returnnil
6977
},

‎cli/autostart_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestAutostart(t *testing.T) {
4545

4646
err=cmd.Execute()
4747
require.NoError(t,err,"unexpected error")
48-
require.Contains(t,stdoutBuf.String(),"schedule: "+sched)
48+
// CRON_TZ gets stripped
49+
require.Contains(t,stdoutBuf.String(),"schedule: 30 17 * * 1-5")
4950
})
5051

5152
t.Run("EnableDisableOK",func(t*testing.T) {

‎cli/autostop.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ func autostopShow() *cobra.Command {
6363
returnnil
6464
}
6565

66-
_,_=fmt.Fprintf(cmd.OutOrStdout(),"schedule: %s\nnext: %s\n",workspace.AutostopSchedule,validSchedule.Next(time.Now()))
66+
next:=validSchedule.Next(time.Now())
67+
loc,_:=time.LoadLocation(validSchedule.Timezone())
68+
69+
_,_=fmt.Fprintf(cmd.OutOrStdout(),
70+
"schedule: %s\ntimezone: %s\nnext: %s\n",
71+
validSchedule.Cron(),
72+
validSchedule.Timezone(),
73+
next.In(loc),
74+
)
6775

6876
returnnil
6977
},

‎cli/autostop_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ func TestAutostop(t *testing.T) {
4545

4646
err=cmd.Execute()
4747
require.NoError(t,err,"unexpected error")
48-
require.Contains(t,stdoutBuf.String(),"schedule: "+sched)
48+
// CRON_TZ gets stripped
49+
require.Contains(t,stdoutBuf.String(),"schedule: 30 17 * * 1-5")
4950
})
5051

5152
t.Run("EnableDisableOK",func(t*testing.T) {

‎cli/list.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/spf13/cobra"
1111

1212
"github.com/coder/coder/cli/cliui"
13+
"github.com/coder/coder/coderd/autobuild/schedule"
1314
"github.com/coder/coder/coderd/database"
1415
"github.com/coder/coder/codersdk"
1516
)
@@ -108,14 +109,18 @@ func list() *cobra.Command {
108109
durationDisplay=durationDisplay[:len(durationDisplay)-2]
109110
}
110111

111-
autostartDisplay:="not enabled"
112+
autostartDisplay:="-"
112113
ifworkspace.AutostartSchedule!="" {
113-
autostartDisplay=workspace.AutostartSchedule
114+
ifsched,err:=schedule.Weekly(workspace.AutostartSchedule);err==nil {
115+
autostartDisplay=sched.Cron()
116+
}
114117
}
115118

116-
autostopDisplay:="not enabled"
119+
autostopDisplay:="-"
117120
ifworkspace.AutostopSchedule!="" {
118-
autostopDisplay=workspace.AutostopSchedule
121+
ifsched,err:=schedule.Weekly(workspace.AutostopSchedule);err==nil {
122+
autostopDisplay=sched.Cron()
123+
}
119124
}
120125

121126
user:=usersByID[workspace.OwnerID]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp