()
| 13 | ) |
| 14 | |
| 15 | func (r *RootCmd) taskStatus() *serpent.Command { |
| 16 | var ( |
| 17 | formatter = cliui.NewOutputFormatter( |
| 18 | cliui.TableFormat( |
| 19 | []taskStatusRow{}, |
| 20 | []string{ |
| 21 | "state changed", |
| 22 | "status", |
| 23 | "healthy", |
| 24 | "state", |
| 25 | "message", |
| 26 | }, |
| 27 | ), |
| 28 | cliui.ChangeFormatterData( |
| 29 | cliui.JSONFormat(), |
| 30 | func(data any) (any, error) { |
| 31 | rows, ok := data.([]taskStatusRow) |
| 32 | if !ok { |
| 33 | return nil, xerrors.Errorf("expected []taskStatusRow, got %T", data) |
| 34 | } |
| 35 | if len(rows) != 1 { |
| 36 | return nil, xerrors.Errorf("expected exactly 1 row, got %d", len(rows)) |
| 37 | } |
| 38 | return rows[0], nil |
| 39 | }, |
| 40 | ), |
| 41 | ) |
| 42 | watchArg bool |
| 43 | watchIntervalArg time.Duration |
| 44 | ) |
| 45 | cmd := &serpent.Command{ |
| 46 | Short: "Show the status of a task.", |
| 47 | Long: FormatExamples( |
| 48 | Example{ |
| 49 | Description: "Show the status of a given task.", |
| 50 | Command: "coder task status task1", |
| 51 | }, |
| 52 | Example{ |
| 53 | Description: "Watch the status of a given task until it completes (idle or stopped).", |
| 54 | Command: "coder task status task1 --watch", |
| 55 | }, |
| 56 | ), |
| 57 | Use: "status", |
| 58 | Aliases: []string{"stat"}, |
| 59 | Options: serpent.OptionSet{ |
| 60 | { |
| 61 | Default: "false", |
| 62 | Description: "Watch the task status output. This will stream updates to the terminal until the underlying workspace is stopped.", |
| 63 | Flag: "watch", |
| 64 | Name: "watch", |
| 65 | Value: serpent.BoolOf(&watchArg), |
| 66 | }, |
| 67 | { |
| 68 | Default: "1s", |
| 69 | Description: "Interval to poll the task for updates. Only used in tests.", |
| 70 | Hidden: true, |
| 71 | Flag: "watch-interval", |
| 72 | Name: "watch-interval", |
no test coverage detected