Commit ff76443
feat(init): support org/project positional to pin org and project name (#428)
## Summary
Redesign `sentry init` to support smart positional arguments for
org/project targeting and directory specification.
### Supported forms
```
sentry init # auto-detect everything, dir = cwd
sentry init . # dir = cwd, auto-detect org
sentry init ./subdir # dir = subdir, auto-detect org
sentry init acme/ # explicit org, dir = cwd
sentry init acme/my-app # explicit org + project, dir = cwd
sentry init my-app # search for project across orgs → sets org + project
sentry init acme/ ./subdir # explicit org, dir = subdir
sentry init acme/my-app ./subdir # explicit org + project, dir = subdir
sentry init ./subdir acme/ # swapped → auto-correct with warning
sentry init ./subdir acme/my-app # swapped → auto-correct with warning
```
### Design
Two optional positionals with smart disambiguation:
- **Path-like args** (starting with `.` `/` `~` `~/`) are treated as the
**directory**
- **Everything else** is treated as the **org/project target**
- When args are in wrong order (path first, target second), they are
**auto-swapped with a warning** — following the established swap pattern
from view commands
- **Bare slugs** (e.g., `my-app`) are resolved via
`resolveProjectBySlug` to search across all accessible orgs, setting
both org and project from the match
- **Two paths** or **two targets** → error with helpful message
- User-provided org/project slugs are validated via `validateResourceId`
at parse time; API-resolved values from `resolveProjectBySlug` skip
redundant validation
### Files changed
| File | Change |
|---|---|
| `src/lib/arg-parsing.ts` | Add `looksLikePath()` for syntactic path
detection (no filesystem I/O) |
| `src/commands/init.ts` | Two positionals, `classifyArgs()`
disambiguation, `resolveTarget()` with `resolveProjectBySlug` for bare
slugs, `validateResourceId` on user-provided slugs only |
| `src/lib/init/types.ts` | Add `org?` and `project?` to `WizardOptions`
|
| `src/lib/init/local-ops.ts` | Use `options.org`/`options.project` in
`createSentryProject()` to skip interactive org resolution and override
wizard-detected project name |
| `test/commands/init.test.ts` | 26 tests covering all arg combinations,
swap detection, error cases |
### Breaking change
`sentry init <directory>` no longer works for bare directory names
(e.g., `sentry init mydir`). Use path syntax: `sentry init ./mydir`.
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>1 parent 94c3727 commit ff76443
6 files changed
Lines changed: 487 additions & 73 deletions
File tree
- plugins/sentry-cli/skills/sentry-cli
- src
- commands
- lib
- init
- test/commands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
727 | 727 | | |
728 | 728 | | |
729 | 729 | | |
730 | | - | |
| 730 | + | |
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
7 | 18 | | |
8 | 19 | | |
9 | 20 | | |
10 | 21 | | |
| 22 | + | |
11 | 23 | | |
| 24 | + | |
12 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
13 | 31 | | |
14 | 32 | | |
15 | 33 | | |
| 34 | + | |
| 35 | + | |
16 | 36 | | |
17 | 37 | | |
18 | 38 | | |
19 | 39 | | |
20 | 40 | | |
21 | 41 | | |
22 | 42 | | |
23 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
24 | 140 | | |
25 | 141 | | |
26 | 142 | | |
27 | 143 | | |
28 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
29 | 155 | | |
30 | 156 | | |
31 | 157 | | |
32 | 158 | | |
33 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
34 | 166 | | |
35 | 167 | | |
36 | 168 | | |
| |||
69 | 201 | | |
70 | 202 | | |
71 | 203 | | |
72 | | - | |
73 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
74 | 220 | | |
75 | 221 | | |
76 | 222 | | |
77 | 223 | | |
78 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
79 | 232 | | |
80 | 233 | | |
81 | 234 | | |
82 | 235 | | |
83 | 236 | | |
84 | 237 | | |
| 238 | + | |
| 239 | + | |
85 | 240 | | |
86 | 241 | | |
87 | 242 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
113 | 159 | | |
114 | 160 | | |
115 | 161 | | |
| |||
0 commit comments