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

Commit9f66395

Browse files
chore(cli): reduce clutter fromexp tasks list command (#19727)
Fixes#19623- Stop showing the long ID of each task by default.- Add new `--quiet` flag to only show IDs.
1 parent2701d55 commit9f66395

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

‎cli/exp_tasklist.go‎renamed to ‎cli/exp_task_list.go‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func (r *RootCmd) taskList() *serpent.Command {
3636
statusFilterstring
3737
allbool
3838
userstring
39+
quietbool
3940

4041
client=new(codersdk.Client)
4142
formatter=cliui.NewOutputFormatter(
4243
cliui.TableFormat(
4344
[]taskListRow{},
4445
[]string{
45-
"id",
4646
"name",
4747
"status",
4848
"state",
@@ -98,6 +98,14 @@ func (r *RootCmd) taskList() *serpent.Command {
9898
Default:"",
9999
Value:serpent.StringOf(&user),
100100
},
101+
{
102+
Name:"quiet",
103+
Description:"Only display task IDs.",
104+
Flag:"quiet",
105+
FlagShorthand:"q",
106+
Default:"false",
107+
Value:serpent.BoolOf(&quiet),
108+
},
101109
},
102110
Handler:func(inv*serpent.Invocation)error {
103111
ctx:=inv.Context()
@@ -116,6 +124,14 @@ func (r *RootCmd) taskList() *serpent.Command {
116124
returnxerrors.Errorf("list tasks: %w",err)
117125
}
118126

127+
ifquiet {
128+
for_,task:=rangetasks {
129+
_,_=fmt.Fprintln(inv.Stdout,task.ID.String())
130+
}
131+
132+
returnnil
133+
}
134+
119135
// If no rows and not JSON, show a friendly message.
120136
iflen(tasks)==0&&formatter.FormatID()!=cliui.JSONFormat().ID() {
121137
_,_=fmt.Fprintln(inv.Stderr,"No tasks found.")

‎cli/exp_tasklist_test.go‎renamed to ‎cli/exp_task_list_test.go‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"database/sql"
77
"encoding/json"
88
"io"
9+
"slices"
10+
"strings"
911
"testing"
1012

1113
"github.com/google/uuid"
@@ -200,6 +202,43 @@ func TestExpTaskList(t *testing.T) {
200202

201203
pty.ExpectMatch(ws.Name)
202204
})
205+
206+
t.Run("Quiet",func(t*testing.T) {
207+
t.Parallel()
208+
209+
// Quiet logger to reduce noise.
210+
quiet:=slog.Make(sloghuman.Sink(io.Discard))
211+
client,db:=coderdtest.NewWithDatabase(t,&coderdtest.Options{Logger:&quiet})
212+
owner:=coderdtest.CreateFirstUser(t,client)
213+
memberClient,memberUser:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
214+
215+
// Given: We have two tasks
216+
task1:=makeAITask(t,db,owner.OrganizationID,owner.UserID,memberUser.ID,database.WorkspaceTransitionStart,"keep me running")
217+
task2:=makeAITask(t,db,owner.OrganizationID,owner.UserID,memberUser.ID,database.WorkspaceTransitionStop,"stop me please")
218+
219+
// Given: We add the `--quiet` flag
220+
inv,root:=clitest.New(t,"exp","task","list","--quiet")
221+
clitest.SetupConfig(t,memberClient,root)
222+
223+
ctx:=testutil.Context(t,testutil.WaitShort)
224+
varstdout bytes.Buffer
225+
inv.Stdout=&stdout
226+
inv.Stderr=&stdout
227+
228+
// When: We run the command
229+
err:=inv.WithContext(ctx).Run()
230+
require.NoError(t,err)
231+
232+
want:= []string{task1.ID.String(),task2.ID.String()}
233+
got:=slice.Filter(strings.Split(stdout.String(),"\n"),func(sstring)bool {
234+
returnlen(s)!=0
235+
})
236+
237+
slices.Sort(want)
238+
slices.Sort(got)
239+
240+
require.Equal(t,want,got)
241+
})
203242
}
204243

205244
funcTestExpTaskList_OwnerCanListOthers(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp