mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
+18
-6
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user