Commit 6aece4f
feat(cli): add pipe support to stop, start, delete, and ls commands (#283)
* feat(cli): add pipe support to stop, start, delete, and ls commands
Add stdin piping and improved output for CLI composability.
Stop/Start/Delete:
- Accept instance names from stdin (one per line)
- Accept multiple instance names as arguments
- Output instance names when piped for chaining
- Add --all flag to stop command
Ls improvements:
- Add --json flag for JSON output
- Output plain table when piped (for grep/awk)
- Add JSON and pipe support to ls orgs
Examples:
brev ls | awk '/RUNNING/ {print $1}' | brev stop
brev ls | grep "test-" | awk '{print $1}' | brev delete
brev ls --json | jq '.[] | select(.status == "RUNNING")'
brev stop --all
* refactor: extract helper functions to reduce cognitive complexity
- Extract trackLsAnalytics() in ls.go
- Extract runBatchStart() and runSingleStart() in start.go
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: extract piping utilities to shared pkg/cmd/util/piping.go
- Consolidate duplicate isStdoutPiped() from delete, ls, start, stop
- Consolidate duplicate getInstanceNames() from delete, stop
- Consolidate duplicate getInstanceNamesFromStdin() from start
- Create IsStdoutPiped(), IsStdinPiped(), GetInstanceNames(), GetInstanceNamesWithPipeInfo()
- Remove ~108 lines of duplicated code
* fix: address PR review comments for piping-composability
- Return errors from runBatchStart instead of silently swallowing them
- Remove unused Piped field from StartOptions
- Add scanner.Err() check after stdin scan loop in piping.go
* feat: add exit code support for partial batch failures
- Add ExitCodeError type to distinguish failure modes
- Batch start returns exit code 2 for partial failure, 1 for all failed
- main.go propagates custom exit codes from ExitCodeError
* feat: add exit code support for partial batch failures in stop
* fix: only pipe output to stdout on full success
Address drewmalin's review: don't send names to stdout when there are
partial failures, since the next piped command would act on them even
without pipefail. Also send admin delete message to stderr instead of
stdout, and remove unused ExitCodeError type.
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent ca0ca77 commit 6aece4f
5 files changed
Lines changed: 404 additions & 82 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | | - | |
42 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | 51 | | |
| 52 | + | |
| 53 | + | |
45 | 54 | | |
46 | 55 | | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
50 | 65 | | |
51 | 66 | | |
52 | 67 | | |
53 | 68 | | |
54 | 69 | | |
55 | 70 | | |
56 | 71 | | |
57 | | - | |
| 72 | + | |
58 | 73 | | |
59 | 74 | | |
60 | | - | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
63 | 78 | | |
| |||
75 | 90 | | |
76 | 91 | | |
77 | 92 | | |
78 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
79 | 96 | | |
80 | 97 | | |
81 | 98 | | |
82 | 99 | | |
83 | | - | |
| 100 | + | |
84 | 101 | | |
85 | 102 | | |
86 | 103 | | |
| |||
89 | 106 | | |
90 | 107 | | |
91 | 108 | | |
92 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
93 | 112 | | |
94 | 113 | | |
95 | 114 | | |
| |||
0 commit comments