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

Allows passing `--quiet` (or `-q`) to the task create command so that it
only prints the ID of the task.
This commit is contained in:
Danielle Maywood
2025-09-04 10:03:22 +01:00
committed by GitHub
parent f867a9d481
commit f94abfc83e
2 changed files with 30 additions and 9 deletions
+18 -6
View File
@@ -22,6 +22,7 @@ func (r *RootCmd) taskCreate() *serpent.Command {
templateVersionName string
presetName string
stdin bool
quiet bool
)
cmd := &serpent.Command{
@@ -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 (
@@ -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
},