()
| 16 | ) |
| 17 | |
| 18 | func (r *RootCmd) taskSend() *serpent.Command { |
| 19 | var stdin bool |
| 20 | |
| 21 | cmd := &serpent.Command{ |
| 22 | Use: "send <task> [<input> | --stdin]", |
| 23 | Short: "Send input to a task", |
| 24 | Long: `Send input to a task. If the task is paused, it will be automatically resumed before input is sent. If the task is initializing, it will wait for the task to become ready. |
| 25 | ` + |
| 26 | FormatExamples(Example{ |
| 27 | Description: "Send direct input to a task", |
| 28 | Command: `coder task send task1 "Please also add unit tests"`, |
| 29 | }, Example{ |
| 30 | Description: "Send input from stdin to a task", |
| 31 | Command: `echo "Please also add unit tests" | coder task send task1 --stdin`, |
| 32 | }), |
| 33 | Middleware: serpent.RequireRangeArgs(1, 2), |
| 34 | Options: serpent.OptionSet{ |
| 35 | { |
| 36 | Name: "stdin", |
| 37 | Flag: "stdin", |
| 38 | Description: "Reads the input from stdin.", |
| 39 | Value: serpent.BoolOf(&stdin), |
| 40 | }, |
| 41 | }, |
| 42 | Handler: func(inv *serpent.Invocation) error { |
| 43 | client, err := r.InitClient(inv) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | var ( |
| 49 | ctx = inv.Context() |
| 50 | identifier = inv.Args[0] |
| 51 | |
| 52 | taskInput string |
| 53 | ) |
| 54 | |
| 55 | if stdin { |
| 56 | bytes, err := io.ReadAll(inv.Stdin) |
| 57 | if err != nil { |
| 58 | return xerrors.Errorf("reading stdio: %w", err) |
| 59 | } |
| 60 | |
| 61 | taskInput = string(bytes) |
| 62 | } else { |
| 63 | if len(inv.Args) != 2 { |
| 64 | return xerrors.Errorf("expected an input for the task") |
| 65 | } |
| 66 | |
| 67 | taskInput = inv.Args[1] |
| 68 | } |
| 69 | |
| 70 | task, err := client.TaskByIdentifier(ctx, identifier) |
| 71 | if err != nil { |
| 72 | return xerrors.Errorf("resolve task: %w", err) |
| 73 | } |
| 74 | |
| 75 | display := fmt.Sprintf("%s/%s", task.OwnerName, task.Name) |
no test coverage detected