@guanghechen/commander 4.7.5 → 4.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.7.7
4
+
5
+ ### Patch Changes
6
+
7
+ - Improve preset schema naming consistency and extend envFile preset-path resolution test coverage.
8
+ Stabilize commander test coverage thresholds.
9
+
10
+ ## 4.7.6
11
+
12
+ ### Patch Changes
13
+
14
+ - Auto-generated release notes:
15
+ - @guanghechen/commander
16
+ - 59f8231 :sparkles: feat(commander): add preset config schema and build-time schema copy
17
+ - 6fc5ee3 :sparkles: feat(commander)!: remove preset suitable restriction
18
+ - 60a6d31 :sparkles: feat(commander): support preset profile variants and manifest presets
19
+
3
20
  ## 4.7.5
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -209,52 +209,59 @@ new Command({ name: 'example', desc: 'Option types demo' })
209
209
  })
210
210
  ```
211
211
 
212
- ### Preset Input Files
212
+ ### Preset Profiles
213
213
 
214
- `--preset-opts=<file>` and `--preset-envs=<file>` allow injecting preset argv and
215
- env inputs before normal CLI parsing.
214
+ Use `--preset-file` with an optional `--preset-profile=<profile[:variant]>` to load profile-based presets.
216
215
 
217
216
  ```bash
218
- mycli --preset-opts=./options.argv --preset-envs=./preset.env --log-level debug --color
217
+ mycli run --preset-file=./preset.json --preset-profile=dev:staging
218
+ ```
219
+
220
+ `preset.json` example:
221
+
222
+ ```json
223
+ {
224
+ "version": 1,
225
+ "defaults": { "profile": "dev" },
226
+ "profiles": {
227
+ "dev": {
228
+ "envFile": "dev.env",
229
+ "envs": { "NODE_ENV": "development" },
230
+ "opts": { "mode": "fast", "retry": 2 },
231
+ "defaultVariant": "local",
232
+ "variants": {
233
+ "local": {
234
+ "opts": { "retry": 1 }
235
+ },
236
+ "staging": {
237
+ "envFile": "staging.env",
238
+ "envs": { "NODE_ENV": "staging" },
239
+ "opts": { "retry": 3 }
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ Schema:
248
+
249
+ ```json
250
+ {
251
+ "$schema": "./node_modules/@guanghechen/commander/lib/schema/preset.schema.json"
252
+ }
219
253
  ```
220
254
 
221
255
  Behavior:
222
256
 
223
- 1. Route command chain from user argv (name/alias only, no argv rewrite), then store route tokens in `sources.user.cmds`.
224
- 2. Run `control-scan` on user tail argv before preset merge: detect `--help` / `--version` by token scan (`--version` only when `supportsBuiltinVersion(leaf)`), detect `help` only when it is the first tail token, write `ctx.controls`, and strip control tokens from parse input.
225
- 3. In `run()`, execute `run-control` before preset merge: short-circuit by `help > version`. If short-circuit hits, preset files are not loaded.
226
- 4. Scan preset directives before `--`, remove them from control-tail argv, and store cleaned tokens in `sources.user.argv`.
227
- 5. Read options preset file(s) and tokenize by whitespace to `sources.preset.argv`.
228
- 6. Read env preset file(s) and parse via `@guanghechen/env.parse` to `sources.preset.envs`.
229
- 7. Build `effectiveTailArgv = [...sources.preset.argv, ...sources.user.argv]`.
230
- 8. Build `ctx.envs = { ...sources.user.envs, ...sources.preset.envs }`.
231
- 9. Expose source snapshots through `ctx.sources` and reuse existing tokenize/resolve/parse pipeline.
232
-
233
- Precedence for same option key:
234
-
235
- 1. User CLI tokens (highest)
236
- 2. Tokens loaded from `--preset-opts`
237
- 3. Option `default` / implicit defaults
238
- 4. `NO_COLOR` fallback for color rendering only (applies only when no explicit `--color/--no-color` token appears)
239
-
240
- Precedence for same env key:
241
-
242
- 1. Key-values loaded from `--preset-envs` (highest)
243
- 2. User envs (e.g. `process.env`)
244
-
245
- Additional notes:
246
-
247
- 1. `variadic` options append in appearance order.
248
- 2. `NO_COLOR` is evaluated from `ctx.envs` and remains a fallback only when no color token is explicitly provided.
249
- 3. The `--preset-opts` file is expected to contain option fragments (`-x`/`--xxx` and their values), not command-route tokens.
250
- 4. The `--preset-envs` file must be parseable by `@guanghechen/env`.
251
- 5. Only preset flags before `--` are processed; after `--` they are treated as normal args.
252
- 6. Repeated preset flags are processed in appearance order.
253
- 7. Built-in control semantics recognize `--help` / `help` / `--version` only (no short aliases).
254
- 8. `long: 'help'` and `long: 'version'` are reserved and must not be user-defined in `.option()`.
255
- 9. `--help` / `help` / `--version` are forbidden in `--preset-opts` files; loading should fail fast.
256
- 10. `--` is forbidden inside `--preset-opts` files; loading should fail fast.
257
- 11. `parse()` never executes control handlers; it only records control hits in `ctx.controls`.
257
+ 1. Profile selector resolution order is `--preset-profile` > `command.preset.profile` > `defaults.profile`.
258
+ 2. Selector supports `<profile>` and `<profile>:<variant>`; when variant is omitted it falls back to `profile.defaultVariant`.
259
+ 3. `envFile` is optional and resolved relative to the preset file directory when not absolute.
260
+ 4. Variant fields override base profile fields by `base + variant`.
261
+ 5. `opts` are converted into preset option fragments and merged before user CLI tokens.
262
+ 6. `envs` override keys loaded from `envFile`.
263
+ 7. Only `--preset-file` / `--preset-profile` are supported as preset directives.
264
+ 8. `--preset-root` is removed.
258
265
 
259
266
  ### Built-in Coerce Factories
260
267