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

Commit78b1ec9

Browse files
authored
feat(cli): add optional --name arg to 'exp task create' (#19939)
Allows specifying task name in `exp task create`
1 parent6d0943a commit78b1ec9

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

‎cli/exp_task_create.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
1717
var (
1818
orgContext=NewOrganizationContext()
1919

20+
taskNamestring
2021
templateNamestring
2122
templateVersionNamestring
2223
presetNamestring
@@ -31,6 +32,14 @@ func (r *RootCmd) taskCreate() *serpent.Command {
3132
serpent.RequireRangeArgs(0,1),
3233
),
3334
Options: serpent.OptionSet{
35+
{
36+
Name:"name",
37+
Flag:"name",
38+
Description:"Specify the name of the task. If you do not specify one, a name will be generated for you.",
39+
Value:serpent.StringOf(&taskName),
40+
Required:false,
41+
Default:"",
42+
},
3443
{
3544
Name:"template",
3645
Flag:"template",
@@ -169,6 +178,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
169178
}
170179

171180
task,err:=expClient.CreateTask(ctx,codersdk.Me, codersdk.CreateTaskRequest{
181+
Name:taskName,
172182
TemplateVersionID:templateVersionID,
173183
TemplateVersionPresetID:templateVersionPresetID,
174184
Prompt:taskInput,

‎cli/exp_task_create_test.go‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestTaskCreate(t *testing.T) {
3434
taskID=uuid.New()
3535
)
3636

37-
templateAndVersionFoundHandler:=func(t*testing.T,ctx context.Context,orgID uuid.UUID,templateName,templateVersionName,presetName,promptstring) http.HandlerFunc {
37+
templateAndVersionFoundHandler:=func(t*testing.T,ctx context.Context,orgID uuid.UUID,templateName,templateVersionName,presetName,prompt,taskNamestring) http.HandlerFunc {
3838
t.Helper()
3939

4040
returnfunc(w http.ResponseWriter,r*http.Request) {
@@ -84,11 +84,17 @@ func TestTaskCreate(t *testing.T) {
8484
assert.Equal(t,templateVersionPresetID,req.TemplateVersionPresetID,"template version preset id mismatch")
8585
}
8686

87-
httpapi.Write(ctx,w,http.StatusCreated, codersdk.Task{
87+
created:= codersdk.Task{
8888
ID:taskID,
89-
Name:"task-wild-goldfish-27",
89+
Name:taskName,
9090
CreatedAt:taskCreatedAt,
91-
})
91+
}
92+
ifreq.Name!="" {
93+
assert.Equal(t,req.Name,taskName,"name mismatch")
94+
created.Name=req.Name
95+
}
96+
97+
httpapi.Write(ctx,w,http.StatusCreated,created)
9298
default:
9399
t.Errorf("unexpected path: %s",r.URL.Path)
94100
}
@@ -108,73 +114,80 @@ func TestTaskCreate(t *testing.T) {
108114
stdin:"reads prompt from stdin",
109115
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
110116
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
111-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","reads prompt from stdin")
117+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","reads prompt from stdin","task-wild-goldfish-27")
112118
},
113119
},
114120
{
115121
args: []string{"my custom prompt"},
116122
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
117123
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
118-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
124+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
125+
},
126+
},
127+
{
128+
args: []string{"--name","abc123","my custom prompt"},
129+
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("abc123"),cliui.Timestamp(taskCreatedAt)),
130+
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
131+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","abc123")
119132
},
120133
},
121134
{
122135
args: []string{"my custom prompt","--template","my-template","--template-version","my-template-version","--org",organizationID.String()},
123136
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
124137
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
125-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
138+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
126139
},
127140
},
128141
{
129142
args: []string{"my custom prompt","--template","my-template","--org",organizationID.String()},
130143
env: []string{"CODER_TASK_TEMPLATE_VERSION=my-template-version"},
131144
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
132145
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
133-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
146+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
134147
},
135148
},
136149
{
137150
args: []string{"my custom prompt","--org",organizationID.String()},
138151
env: []string{"CODER_TASK_TEMPLATE_NAME=my-template","CODER_TASK_TEMPLATE_VERSION=my-template-version"},
139152
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
140153
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
141-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
154+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
142155
},
143156
},
144157
{
145158
args: []string{"my custom prompt","--template","my-template","--org",organizationID.String()},
146159
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
147160
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
148-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","","my custom prompt")
161+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","","my custom prompt","task-wild-goldfish-27")
149162
},
150163
},
151164
{
152165
args: []string{"my custom prompt","--template","my-template","--preset","my-preset","--org",organizationID.String()},
153166
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
154167
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
155-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt")
168+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
156169
},
157170
},
158171
{
159172
args: []string{"my custom prompt","--template","my-template"},
160173
env: []string{"CODER_TASK_PRESET_NAME=my-preset"},
161174
expectOutput:fmt.Sprintf("The task %s has been created at %s!",cliui.Keyword("task-wild-goldfish-27"),cliui.Timestamp(taskCreatedAt)),
162175
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
163-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt")
176+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
164177
},
165178
},
166179
{
167180
args: []string{"my custom prompt","-q"},
168181
expectOutput:taskID.String(),
169182
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
170-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt")
183+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","my-template-version","","my custom prompt","task-wild-goldfish-27")
171184
},
172185
},
173186
{
174187
args: []string{"my custom prompt","--template","my-template","--preset","not-real-preset"},
175188
expectError:`preset "not-real-preset" not found`,
176189
handler:func(t*testing.T,ctx context.Context) http.HandlerFunc {
177-
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt")
190+
returntemplateAndVersionFoundHandler(t,ctx,organizationID,"my-template","","my-preset","my custom prompt","task-wild-goldfish-27")
178191
},
179192
},
180193
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp