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

feat(cli): add quiet flag to task create#19701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DanielleMaywood merged 1 commit intomainfromdanielle/tasks/quiet-flag-create
Sep 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletionscli/exp_task_create.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
templateVersionName string
presetName string
stdin bool
quiet bool
)

cmd := &serpent.Command{
Expand DownExpand Up@@ -57,6 +58,13 @@ func (r *RootCmd) taskCreate() *serpent.Command {
Description: "Reads from stdin for the task input.",
Value: serpent.BoolOf(&stdin),
},
{
Name: "quiet",
Flag: "quiet",
FlagShorthand: "q",
Description: "Only display the created task's ID.",
Value: serpent.BoolOf(&quiet),
},
},
Handler: func(inv *serpent.Invocation) error {
var (
Expand DownExpand Up@@ -166,12 +174,16 @@ func (r *RootCmd) taskCreate() *serpent.Command {
return xerrors.Errorf("create task: %w", err)
}

_, _ = fmt.Fprintf(
inv.Stdout,
"The task %s has been created at %s!\n",
cliui.Keyword(task.Name),
cliui.Timestamp(task.CreatedAt),
)
if quiet {
_, _ = fmt.Fprintln(inv.Stdout, task.ID)
} else {
_, _ = fmt.Fprintf(
inv.Stdout,
"The task %s has been created at %s!\n",
cliui.Keyword(task.Name),
cliui.Timestamp(task.CreatedAt),
)
}

return nil
},
Expand Down
15 changes: 12 additions & 3 deletionscli/exp_task_create_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,7 @@ func TestTaskCreate(t *testing.T) {
templateID = uuid.New()
templateVersionID = uuid.New()
templateVersionPresetID = uuid.New()
taskID = uuid.New()
)

templateAndVersionFoundHandler := func(t *testing.T, ctx context.Context, orgID uuid.UUID, templateName, templateVersionName, presetName, prompt string) http.HandlerFunc {
Expand All@@ -44,11 +45,11 @@ func TestTaskCreate(t *testing.T) {
ID: orgID,
}},
})
case fmt.Sprintf("/api/v2/organizations/%s/templates/my-template/versions/my-template-version", orgID):
case fmt.Sprintf("/api/v2/organizations/%s/templates/%s/versions/%s", orgID, templateName, templateVersionName):
httpapi.Write(ctx, w, http.StatusOK, codersdk.TemplateVersion{
ID: templateVersionID,
})
case fmt.Sprintf("/api/v2/organizations/%s/templates/my-template", orgID):
case fmt.Sprintf("/api/v2/organizations/%s/templates/%s", orgID, templateName):
Comment on lines +48 to +52
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

drive-by test fix

httpapi.Write(ctx, w, http.StatusOK, codersdk.Template{
ID: templateID,
ActiveVersionID: templateVersionID,
Expand DownExpand Up@@ -83,7 +84,8 @@ func TestTaskCreate(t *testing.T) {
assert.Equal(t, templateVersionPresetID, req.TemplateVersionPresetID, "template version preset id mismatch")
}

httpapi.Write(ctx, w, http.StatusCreated, codersdk.Workspace{
httpapi.Write(ctx, w, http.StatusCreated, codersdk.Task{
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

drive-by test fix

ID: taskID,
Name: "task-wild-goldfish-27",
CreatedAt: taskCreatedAt,
})
Expand DownExpand Up@@ -161,6 +163,13 @@ func TestTaskCreate(t *testing.T) {
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "", "my-preset", "my custom prompt")
},
},
{
args: []string{"my custom prompt", "-q"},
expectOutput: taskID.String(),
handler: func(t *testing.T, ctx context.Context) http.HandlerFunc {
return templateAndVersionFoundHandler(t, ctx, organizationID, "my-template", "my-template-version", "", "my custom prompt")
},
},
{
args: []string{"my custom prompt", "--template", "my-template", "--preset", "not-real-preset"},
expectError: `preset "not-real-preset" not found`,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp