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

Commitf94abfc

Browse files
feat(cli): add quiet flag to task create (#19701)
Allows passing `--quiet` (or `-q`) to the task create command so that itonly prints the ID of the task.
1 parentf867a9d commitf94abfc

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

‎cli/exp_task_create.go‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
2222
templateVersionNamestring
2323
presetNamestring
2424
stdinbool
25+
quietbool
2526
)
2627

2728
cmd:=&serpent.Command{
@@ -57,6 +58,13 @@ func (r *RootCmd) taskCreate() *serpent.Command {
5758
Description:"Reads from stdin for the task input.",
5859
Value:serpent.BoolOf(&stdin),
5960
},
61+
{
62+
Name:"quiet",
63+
Flag:"quiet",
64+
FlagShorthand:"q",
65+
Description:"Only display the created task's ID.",
66+
Value:serpent.BoolOf(&quiet),
67+
},
6068
},
6169
Handler:func(inv*serpent.Invocation)error {
6270
var (
@@ -166,12 +174,16 @@ func (r *RootCmd) taskCreate() *serpent.Command {
166174
returnxerrors.Errorf("create task: %w",err)
167175
}
168176

169-
_,_=fmt.Fprintf(
170-
inv.Stdout,
171-
"The task %s has been created at %s!\n",
172-
cliui.Keyword(task.Name),
173-
cliui.Timestamp(task.CreatedAt),
174-
)
177+
ifquiet {
178+
_,_=fmt.Fprintln(inv.Stdout,task.ID)
179+
}else {
180+
_,_=fmt.Fprintf(
181+
inv.Stdout,
182+
"The task %s has been created at %s!\n",
183+
cliui.Keyword(task.Name),
184+
cliui.Timestamp(task.CreatedAt),
185+
)
186+
}
175187

176188
returnnil
177189
},

‎cli/exp_task_create_test.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestTaskCreate(t *testing.T) {
3131
templateID=uuid.New()
3232
templateVersionID=uuid.New()
3333
templateVersionPresetID=uuid.New()
34+
taskID=uuid.New()
3435
)
3536

3637
templateAndVersionFoundHandler:=func(t*testing.T,ctx context.Context,orgID uuid.UUID,templateName,templateVersionName,presetName,promptstring) http.HandlerFunc {
@@ -44,11 +45,11 @@ func TestTaskCreate(t *testing.T) {
4445
ID:orgID,
4546
}},
4647
})
47-
casefmt.Sprintf("/api/v2/organizations/%s/templates/my-template/versions/my-template-version",orgID):
48+
casefmt.Sprintf("/api/v2/organizations/%s/templates/%s/versions/%s",orgID,templateName,templateVersionName):
4849
httpapi.Write(ctx,w,http.StatusOK, codersdk.TemplateVersion{
4950
ID:templateVersionID,
5051
})
51-
casefmt.Sprintf("/api/v2/organizations/%s/templates/my-template",orgID):
52+
casefmt.Sprintf("/api/v2/organizations/%s/templates/%s",orgID,templateName):
5253
httpapi.Write(ctx,w,http.StatusOK, codersdk.Template{
5354
ID:templateID,
5455
ActiveVersionID:templateVersionID,
@@ -83,7 +84,8 @@ func TestTaskCreate(t *testing.T) {
8384
assert.Equal(t,templateVersionPresetID,req.TemplateVersionPresetID,"template version preset id mismatch")
8485
}
8586

86-
httpapi.Write(ctx,w,http.StatusCreated, codersdk.Workspace{
87+
httpapi.Write(ctx,w,http.StatusCreated, codersdk.Task{
88+
ID:taskID,
8789
Name:"task-wild-goldfish-27",
8890
CreatedAt:taskCreatedAt,
8991
})
@@ -161,6 +163,13 @@ func TestTaskCreate(t *testing.T) {
161163
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt")
162164
},
163165
},
166+
{
167+
args: []string{"my custom prompt","-q"},
168+
expectOutput:taskID.String(),
169+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
170+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
171+
},
172+
},
164173
{
165174
args: []string{"my custom prompt","--template","my-template","--preset","not-real-preset"},
166175
expectError:`preset "not-real-preset" not found`,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp