@guanghechen/commander 4.6.0 → 4.7.0

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,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add explicit runtime entry points for browser and node, and align command runtime abstractions and
8
+ tests.
9
+
3
10
  ## 4.6.0
4
11
 
5
12
  ### Minor Changes
package/README.md CHANGED
@@ -73,7 +73,7 @@ parsing, shell completion generation (bash, fish, pwsh), and built-in help/versi
73
73
  ### Basic Command
74
74
 
75
75
  ```typescript
76
- import { Command } from '@guanghechen/commander'
76
+ import { Command } from '@guanghechen/commander/browser'
77
77
 
78
78
  const cli = new Command({
79
79
  name: 'mycli',
@@ -119,7 +119,7 @@ cli.run({
119
119
  ### Subcommands
120
120
 
121
121
  ```typescript
122
- import { Command } from '@guanghechen/commander'
122
+ import { Command } from '@guanghechen/commander/browser'
123
123
 
124
124
  const root = new Command({
125
125
  name: 'git',
@@ -153,7 +153,8 @@ root.run({ argv: process.argv.slice(2), envs: process.env })
153
153
  ### Shell Completion
154
154
 
155
155
  ```typescript
156
- import { Command, CompletionCommand } from '@guanghechen/commander'
156
+ import { Command } from '@guanghechen/commander/browser'
157
+ import { CompletionCommand } from '@guanghechen/commander/node'
157
158
 
158
159
  const root = new Command({
159
160
  name: 'mycli',
@@ -173,7 +174,7 @@ root.subcommand('completion', new CompletionCommand(root))
173
174
  ### Option Types
174
175
 
175
176
  ```typescript
176
- import { Command } from '@guanghechen/commander'
177
+ import { Command } from '@guanghechen/commander/browser'
177
178
 
178
179
  new Command({ name: 'example', desc: 'Option types demo' })
179
180
  // Boolean (flags)
@@ -208,19 +209,16 @@ new Command({ name: 'example', desc: 'Option types demo' })
208
209
  })
209
210
  ```
210
211
 
211
- ### Planned: Preset Input Files
212
+ ### Preset Input Files
212
213
 
213
- > This is a proposed feature and not released yet.
214
- > README is an overview only. Authoritative semantics are defined in `packages/commander/spec/*.md`.
215
-
216
- The proposed `--preset-opts=<file>` and `--preset-envs=<file>` flags allow injecting preset argv and
214
+ `--preset-opts=<file>` and `--preset-envs=<file>` allow injecting preset argv and
217
215
  env inputs before normal CLI parsing.
218
216
 
219
217
  ```bash
220
218
  mycli --preset-opts=./options.argv --preset-envs=./preset.env --log-level debug --color
221
219
  ```
222
220
 
223
- Proposed behavior:
221
+ Behavior:
224
222
 
225
223
  1. Route command chain from user argv (name/alias only, no argv rewrite), then store route tokens in `sources.user.cmds`.
226
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.
@@ -232,14 +230,14 @@ Proposed behavior:
232
230
  8. Build `ctx.envs = { ...sources.user.envs, ...sources.preset.envs }`.
233
231
  9. Expose source snapshots through `ctx.sources` and reuse existing tokenize/resolve/parse pipeline.
234
232
 
235
- Proposed precedence for same option key:
233
+ Precedence for same option key:
236
234
 
237
235
  1. User CLI tokens (highest)
238
236
  2. Tokens loaded from `--preset-opts`
239
237
  3. Option `default` / implicit defaults
240
238
  4. `NO_COLOR` fallback for color rendering only (applies only when no explicit `--color/--no-color` token appears)
241
239
 
242
- Proposed precedence for same env key:
240
+ Precedence for same env key:
243
241
 
244
242
  1. Key-values loaded from `--preset-envs` (highest)
245
243
  2. User envs (e.g. `process.env`)
@@ -261,7 +259,7 @@ Additional notes:
261
259
  ### Built-in Coerce Factories
262
260
 
263
261
  ```typescript
264
- import { Coerce, Command } from '@guanghechen/commander'
262
+ import { Coerce, Command } from '@guanghechen/commander/browser'
265
263
 
266
264
  new Command({ name: 'example', desc: 'Coerce demo' })
267
265
  .option({
@@ -340,7 +338,7 @@ You can still override the message via `Coerce.xxx(name, 'custom error message')
340
338
  ### Built-in Is Helpers
341
339
 
342
340
  ```typescript
343
- import { isDomain, isIp, isIpv4, isIpv6 } from '@guanghechen/commander'
341
+ import { isDomain, isIp, isIpv4, isIpv6 } from '@guanghechen/commander/browser'
344
342
 
345
343
  isIpv4('127.0.0.1') // true
346
344
  isIpv6('::1') // true
@@ -351,7 +349,7 @@ isDomain('example.com') // true
351
349
  ### Help Examples
352
350
 
353
351
  ```typescript
354
- import { Command } from '@guanghechen/commander'
352
+ import { Command } from '@guanghechen/commander/browser'
355
353
 
356
354
  const cli = new Command({ name: 'mycli', desc: 'My CLI tool' })
357
355