@kjanat/dreamcli 2.4.1 → 3.0.0-rc.1
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 +169 -1
- package/README.md +14 -7
- package/dist/core/cli/index.d.mts +283 -81
- package/dist/core/cli/index.mjs +1 -1
- package/dist/core/cli/planner.d.mts +27 -5
- package/dist/core/cli/planner.mjs +1 -1
- package/dist/core/cli/root-help.d.mts +16 -2
- package/dist/core/cli/root-help.mjs +3 -5
- package/dist/core/cli/root-surface.d.mts +18 -3
- package/dist/core/cli/root-surface.mjs +1 -1
- package/dist/core/cli/runtime-preflight.d.mts +31 -5
- package/dist/core/cli/runtime-preflight.mjs +1 -1
- package/dist/core/completion/index.d.mts +32 -1
- package/dist/core/completion/index.mjs +1 -1
- package/dist/core/completion/shells/shared.d.mts +10 -0
- package/dist/core/completion/shells/shared.mjs +1 -1
- package/dist/core/config/index.d.mts +2 -2
- package/dist/core/config/package-json.d.mts +93 -20
- package/dist/core/config/package-json.mjs +3 -1
- package/dist/core/help/index.d.mts +45 -1
- package/dist/core/help/index.mjs +6 -6
- package/dist/core/json-schema/index.mjs +1 -1
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +38 -38
- package/dist/core/parse/index.d.mts +15 -1
- package/dist/core/parse/index.mjs +1 -1
- package/dist/core/prompt/index.d.mts +11 -3
- package/dist/core/prompt/index.mjs +3 -3
- package/dist/core/resolve/coerce.mjs +1 -1
- package/dist/core/resolve/flags.mjs +1 -1
- package/dist/core/resolve/property.d.mts +2 -0
- package/dist/core/resolve/property.mjs +1 -1
- package/dist/core/schema/arg.d.mts +90 -10
- package/dist/core/schema/arg.mjs +1 -1
- package/dist/core/schema/command.d.mts +3 -1
- package/dist/core/schema/flag.d.mts +92 -2
- package/dist/core/schema/flag.mjs +1 -1
- package/dist/core/schema/index.d.mts +2 -1
- package/dist/core/schema/number-constraints.d.mts +96 -0
- package/dist/core/schema/number-constraints.mjs +1 -0
- package/dist/core/schema/prompt.d.mts +15 -0
- package/dist/core/schema/run.d.mts +4 -4
- package/dist/core/testkit/index.d.mts +9 -5
- package/dist/core/testkit/index.mjs +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/runtime/auto.mjs +1 -1
- package/dist/runtime/bun.mjs +1 -1
- package/dist/runtime/deno.mjs +2 -2
- package/dist/runtime/node.mjs +2 -2
- package/dist/version.mjs +1 -1
- package/examples/basic.ts +5 -1
- package/examples/gh/package.json +2 -7
- package/examples/pwsh-demo/package.json +1 -7
- package/examples/pwsh-demo/src/main.test.ts +1 -4
- package/examples/pwsh-demo/src/main.ts +14 -4
- package/examples/transport-launcher.ts +85 -0
- package/package.json +15 -24
- package/src/core/cli/dispatch.ts +7 -1
- package/src/core/cli/index.ts +521 -122
- package/src/core/cli/planner.ts +192 -23
- package/src/core/cli/root-help.ts +195 -105
- package/src/core/cli/root-surface.ts +25 -12
- package/src/core/cli/runtime-preflight.ts +43 -8
- package/src/core/completion/index.ts +50 -0
- package/src/core/completion/shells/powershell.ts +2 -2
- package/src/core/completion/shells/shared.ts +30 -3
- package/src/core/config/index.ts +12 -2
- package/src/core/config/package-json.ts +250 -41
- package/src/core/execution/index.ts +1 -4
- package/src/core/help/index.ts +57 -10
- package/src/core/json-schema/index.ts +23 -4
- package/src/core/json-schema/meta-descriptions.generated.ts +115 -98
- package/src/core/parse/index.ts +62 -1
- package/src/core/prompt/index.ts +54 -14
- package/src/core/resolve/coerce.ts +73 -5
- package/src/core/resolve/flags.ts +14 -0
- package/src/core/resolve/property.ts +4 -4
- package/src/core/schema/arg.ts +125 -3
- package/src/core/schema/command.ts +3 -1
- package/src/core/schema/flag.ts +120 -4
- package/src/core/schema/index.ts +5 -0
- package/src/core/schema/number-constraints.ts +153 -0
- package/src/core/schema/prompt.ts +15 -0
- package/src/core/schema/run.ts +4 -4
- package/src/core/testkit/index.ts +32 -8
- package/src/index.ts +8 -0
- package/src/runtime/auto.ts +0 -24
- package/src/runtime/bun.ts +0 -7
- package/src/runtime/deno.ts +0 -2
- package/src/runtime/node.ts +0 -11
- package/src/runtime/support.ts +1 -59
- package/src/schema.ts +16 -0
- package/dist/runtime/support.d.mts +0 -42
- package/dist/runtime/support.mjs +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NumberConstraints } from "./number-constraints.mjs";
|
|
1
2
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PROMPT_KINDS, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./prompt.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/core/schema/flag.d.ts
|
|
@@ -123,6 +124,13 @@ interface FlagSchema {
|
|
|
123
124
|
readonly description: string | undefined;
|
|
124
125
|
/** Allowed literal values when `kind === 'enum'`. */
|
|
125
126
|
readonly enumValues: readonly string[] | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Numeric constraints when `kind === 'number'` (`undefined` otherwise).
|
|
129
|
+
*
|
|
130
|
+
* Enforced at the parse and resolution boundaries. `finite` defaults to
|
|
131
|
+
* `true`, so `Infinity` is rejected even when no constraints object is set.
|
|
132
|
+
*/
|
|
133
|
+
readonly numberConstraints: NumberConstraints | undefined;
|
|
126
134
|
/** Element schema when `kind === 'array'`. */
|
|
127
135
|
readonly elementSchema: FlagSchema | undefined;
|
|
128
136
|
/** Interactive prompt configuration for v0.3+ resolution. */
|
|
@@ -397,6 +405,71 @@ declare class FlagBuilder<C extends FlagConfig> {
|
|
|
397
405
|
* ```
|
|
398
406
|
*/
|
|
399
407
|
propagate(): FlagBuilder<C>;
|
|
408
|
+
/**
|
|
409
|
+
* Require an integer value. Composes with other numeric constraints.
|
|
410
|
+
*
|
|
411
|
+
* @param value - Whether to require an integer.
|
|
412
|
+
* @defaultValue `true`
|
|
413
|
+
* @returns The builder (for chaining).
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```ts
|
|
417
|
+
* flag.number().int() // rejects 3.7, accepts 3
|
|
418
|
+
* flag.number({ int: true }).int(false) // re-allows non-integers
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
int(this: FlagBuilder<C & {
|
|
422
|
+
readonly flagKind: 'number';
|
|
423
|
+
}>, value?: boolean): FlagBuilder<C>;
|
|
424
|
+
/**
|
|
425
|
+
* Set an inclusive lower bound. Composes with other numeric constraints;
|
|
426
|
+
* a later call overrides an earlier `min` (including one from the options
|
|
427
|
+
* object).
|
|
428
|
+
*
|
|
429
|
+
* @param value - Inclusive minimum.
|
|
430
|
+
* @returns The builder (for chaining).
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```ts
|
|
434
|
+
* flag.number().min(0) // rejects -1, accepts 0
|
|
435
|
+
* flag.number({ min: 0 }).min(5) // effective min is 5
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
min(this: FlagBuilder<C & {
|
|
439
|
+
readonly flagKind: 'number';
|
|
440
|
+
}>, value: number): FlagBuilder<C>;
|
|
441
|
+
/**
|
|
442
|
+
* Set an inclusive upper bound. Composes with other numeric constraints;
|
|
443
|
+
* a later call overrides an earlier `max`.
|
|
444
|
+
*
|
|
445
|
+
* @param value - Inclusive maximum.
|
|
446
|
+
* @returns The builder (for chaining).
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```ts
|
|
450
|
+
* flag.number().max(100) // rejects 101, accepts 100
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
max(this: FlagBuilder<C & {
|
|
454
|
+
readonly flagKind: 'number';
|
|
455
|
+
}>, value: number): FlagBuilder<C>;
|
|
456
|
+
/**
|
|
457
|
+
* Require (or, with `false`, allow) a finite value. Finiteness is enforced
|
|
458
|
+
* by default, so this is mainly used as `.finite(false)` to re-allow
|
|
459
|
+
* `Infinity` / `-Infinity`.
|
|
460
|
+
*
|
|
461
|
+
* @param allow - Whether to require a finite value.
|
|
462
|
+
* @defaultValue `true`
|
|
463
|
+
* @returns The builder (for chaining).
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```ts
|
|
467
|
+
* flag.number().finite(false) // accepts Infinity
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
finite(this: FlagBuilder<C & {
|
|
471
|
+
readonly flagKind: 'number';
|
|
472
|
+
}>, allow?: boolean): FlagBuilder<C>;
|
|
400
473
|
}
|
|
401
474
|
/**
|
|
402
475
|
* Factory that creates {@link FlagBuilder} instances seeded with the correct
|
|
@@ -415,11 +488,28 @@ interface FlagFactory {
|
|
|
415
488
|
readonly flagKind: 'string';
|
|
416
489
|
}>;
|
|
417
490
|
/**
|
|
418
|
-
* Number-valued flag.
|
|
491
|
+
* Number-valued flag, with optional numeric constraints.
|
|
492
|
+
*
|
|
493
|
+
* Constraints are enforced at the parse and resolution boundaries. The
|
|
494
|
+
* resolved value type stays `number` — constraints are runtime + schema, not
|
|
495
|
+
* type-level. Bounds are inclusive.
|
|
419
496
|
*
|
|
497
|
+
* Constraints also compose via chained methods (`.int()`, `.min()`,
|
|
498
|
+
* `.max()`, `.finite()`), which override values set here.
|
|
499
|
+
*
|
|
500
|
+
* @param constraints - Optional numeric constraints. `finite` defaults to
|
|
501
|
+
* `true`, so `Infinity` / `-Infinity` are rejected unless `finite: false`.
|
|
502
|
+
* @defaultValue `undefined` (finite-only, no bounds, non-integer allowed)
|
|
420
503
|
* @returns A {@link FlagBuilder} for `number` values.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```ts
|
|
507
|
+
* flag.number() // finite numbers only
|
|
508
|
+
* flag.number({ int: true, min: 0 }) // non-negative integers
|
|
509
|
+
* flag.number({ finite: false }) // also accepts Infinity
|
|
510
|
+
* ```
|
|
421
511
|
*/
|
|
422
|
-
number(): FlagBuilder<{
|
|
512
|
+
number(constraints?: NumberConstraints): FlagBuilder<{
|
|
423
513
|
readonly valueType: number;
|
|
424
514
|
readonly presence: 'optional';
|
|
425
515
|
readonly optionalFallback: 'undefined';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{assertNumberConstraints as e}from"./number-constraints.mjs";function t(e){return typeof e==`string`?{name:e,hidden:!1}:{name:e.name,hidden:e.hidden}}function n(e){return e.map(t)}function r(e,t){let n=t?.includeHidden??!1,r=t?.kind??`all`;return e.aliases.filter(e=>n||!e.hidden).filter(e=>r===`short`?e.name.length===1:r===`long`?e.name.length>1:!0).map(e=>e.name)}function i(e,t){let r=t?.aliases===void 0?[]:n(t.aliases),{aliases:i,...a}=t??{};return{kind:e,presence:`optional`,defaultValue:void 0,envVar:void 0,configPath:void 0,description:void 0,enumValues:void 0,numberConstraints:void 0,elementSchema:void 0,prompt:void 0,parseFn:void 0,deprecated:void 0,propagate:!1,...a,aliases:r}}var a=class t{schema;constructor(e){this.schema=e}default(e){return new t({...this.schema,presence:`defaulted`,defaultValue:e})}required(){return new t({...this.schema,presence:`required`})}alias(e,n){return new t({...this.schema,aliases:[...this.schema.aliases,{name:e,hidden:n?.hidden??!1}]})}env(e){return new t({...this.schema,envVar:e})}config(e){return new t({...this.schema,configPath:e})}describe(e){return new t({...this.schema,description:e})}prompt(e){return new t({...this.schema,prompt:e})}deprecated(e){return new t({...this.schema,deprecated:e??!0})}propagate(){return new t({...this.schema,propagate:!0})}int(e=!0){return new t({...this.schema,numberConstraints:{...this.schema.numberConstraints,int:e}})}min(n){let r={...this.schema.numberConstraints,min:n};return e(r),new t({...this.schema,numberConstraints:r})}max(n){let r={...this.schema.numberConstraints,max:n};return e(r),new t({...this.schema,numberConstraints:r})}finite(e=!0){return new t({...this.schema,numberConstraints:{...this.schema.numberConstraints,finite:e}})}};const o={string(){return new a(i(`string`))},number(t){return t!==void 0&&e(t),new a(i(`number`,t===void 0?{}:{numberConstraints:t}))},boolean(){return new a(i(`boolean`,{presence:`defaulted`,defaultValue:!1}))},enum(e){return new a(i(`enum`,{enumValues:e}))},array(e){return new a(i(`array`,{elementSchema:e.schema}))},custom(e){return new a(i(`custom`,{parseFn:e}))}};export{a as FlagBuilder,i as createSchema,o as flag,r as getFlagAliasNames};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle, SpinnerOptions, TableColumn, TableFormat, TableOptions, TableStream } from "./activity.mjs";
|
|
2
|
+
import { NumberConstraintViolation, NumberConstraints, describeNumberConstraintViolation, validateNumberConstraints } from "./number-constraints.mjs";
|
|
2
3
|
import { ARG_KINDS, ARG_PRESENCES, ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./arg.mjs";
|
|
3
4
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PROMPT_KINDS, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./prompt.mjs";
|
|
4
5
|
import { FLAG_KINDS, FLAG_PRESENCES, FlagAlias, FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagParseFn, FlagPresence, FlagSchema, FlagSchemaOverrides, InferFlag, InferFlags, ResolvedValue, WithPresence, createSchema, flag } from "./flag.mjs";
|
|
5
6
|
import { ErasedMiddlewareHandler, Middleware, MiddlewareHandler, MiddlewareParams, middleware } from "./middleware.mjs";
|
|
6
7
|
import { RunOptions, RunResult } from "./run.mjs";
|
|
7
8
|
import { ActionHandler, ActionParams, AnyCommandBuilder, CommandArgEntry, CommandBuilder, CommandConfig, CommandExample, CommandMeta, CommandSchema, DeriveHandler, DeriveParams, ErasedCommand, ErasedDeriveHandler, ErasedInteractiveResolver, InteractiveParams, InteractiveResolver, InteractiveResult, Out, command, group } from "./command.mjs";
|
|
8
|
-
export { ARG_KINDS, ARG_PRESENCES, type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type ConfirmPromptConfig, type DeriveHandler, type DeriveParams, type ErasedCommand, type ErasedDeriveHandler, type ErasedInteractiveResolver, type ErasedMiddlewareHandler, FLAG_KINDS, FLAG_PRESENCES, type Fallback, type FlagAlias, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FlagSchemaOverrides, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type Out, PROMPT_KINDS, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptKind, type PromptResult, type ResolvedArgValue, type ResolvedValue, type RunOptions, type RunResult, type SelectChoice, type SelectPromptConfig, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type WithArgPresence, type WithPresence, type WithVariadic, arg, command, createArgSchema, createSchema, flag, group, middleware };
|
|
9
|
+
export { ARG_KINDS, ARG_PRESENCES, type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type ConfirmPromptConfig, type DeriveHandler, type DeriveParams, type ErasedCommand, type ErasedDeriveHandler, type ErasedInteractiveResolver, type ErasedMiddlewareHandler, FLAG_KINDS, FLAG_PRESENCES, type Fallback, type FlagAlias, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FlagSchemaOverrides, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type NumberConstraintViolation, type NumberConstraints, type Out, PROMPT_KINDS, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptKind, type PromptResult, type ResolvedArgValue, type ResolvedValue, type RunOptions, type RunResult, type SelectChoice, type SelectPromptConfig, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type WithArgPresence, type WithPresence, type WithVariadic, arg, command, createArgSchema, createSchema, describeNumberConstraintViolation, flag, group, middleware, validateNumberConstraints };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//#region src/core/schema/number-constraints.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Numeric constraints for number-valued flags and args.
|
|
4
|
+
*
|
|
5
|
+
* A single, shared representation and validator so the parse path
|
|
6
|
+
* (`core/parse`) and the resolver coercion path (`core/resolve/coerce`) cannot
|
|
7
|
+
* drift: both import {@link validateNumberConstraints} and apply the checks in
|
|
8
|
+
* the same order (finite → int → min → max).
|
|
9
|
+
*
|
|
10
|
+
* @module dreamcli/core/schema/number-constraints
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Runtime numeric constraints attached to a number flag/arg schema.
|
|
14
|
+
*
|
|
15
|
+
* Bounds are **inclusive**. All fields are optional; an absent field means "no
|
|
16
|
+
* constraint" except for {@link NumberConstraints.finite | finite}, which
|
|
17
|
+
* defaults to `true` (so `Infinity` / `-Infinity` are rejected unless opted
|
|
18
|
+
* back in).
|
|
19
|
+
*/
|
|
20
|
+
interface NumberConstraints {
|
|
21
|
+
/**
|
|
22
|
+
* Inclusive lower bound. Values below this are rejected.
|
|
23
|
+
* @defaultValue `undefined` (no lower bound)
|
|
24
|
+
*/
|
|
25
|
+
readonly min?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Inclusive upper bound. Values above this are rejected.
|
|
28
|
+
* @defaultValue `undefined` (no upper bound)
|
|
29
|
+
*/
|
|
30
|
+
readonly max?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Require an integer value. Non-integers (e.g. `3.7`) are rejected.
|
|
33
|
+
* @defaultValue `false`
|
|
34
|
+
*/
|
|
35
|
+
readonly int?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Require a finite value. When `true`, `Infinity` / `-Infinity` are rejected.
|
|
38
|
+
* @defaultValue `true`
|
|
39
|
+
*/
|
|
40
|
+
readonly finite?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A failed numeric constraint, discriminated by which rule was violated.
|
|
44
|
+
*
|
|
45
|
+
* `min` / `max` carry the offending bound so callers can render it.
|
|
46
|
+
*/
|
|
47
|
+
type NumberConstraintViolation = {
|
|
48
|
+
readonly kind: 'finite';
|
|
49
|
+
} | {
|
|
50
|
+
readonly kind: 'int';
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: 'min';
|
|
53
|
+
readonly bound: number;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'max';
|
|
56
|
+
readonly bound: number;
|
|
57
|
+
};
|
|
58
|
+
/** Default for {@link NumberConstraints.finite} — reject `Infinity` unless opted out. */
|
|
59
|
+
declare const DEFAULT_FINITE = true;
|
|
60
|
+
/**
|
|
61
|
+
* Validate a numeric value against constraints.
|
|
62
|
+
*
|
|
63
|
+
* The single source of truth for numeric-constraint checks, shared by the
|
|
64
|
+
* parse and coerce paths. Checks run in a fixed order — **finite → int → min →
|
|
65
|
+
* max** — and the first failure is returned. `NaN` is always rejected as a
|
|
66
|
+
* `finite` violation, regardless of the `finite` option (a non-finite value can
|
|
67
|
+
* otherwise slip past `min`/`max`, since `NaN < x` and `NaN > x` are both false).
|
|
68
|
+
*
|
|
69
|
+
* @param value - The numeric value to validate.
|
|
70
|
+
* @param constraints - Constraints to enforce, or `undefined` for defaults.
|
|
71
|
+
* @returns The first {@link NumberConstraintViolation}, or `undefined` if valid.
|
|
72
|
+
*/
|
|
73
|
+
declare function validateNumberConstraints(value: number, constraints: NumberConstraints | undefined): NumberConstraintViolation | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Render a terse, human-readable reason for a constraint violation.
|
|
76
|
+
*
|
|
77
|
+
* @param violation - The violation to describe.
|
|
78
|
+
* @returns A message suffix such as `must be an integer` or `must be >= 0`.
|
|
79
|
+
*/
|
|
80
|
+
declare function describeNumberConstraintViolation(violation: NumberConstraintViolation): string;
|
|
81
|
+
/**
|
|
82
|
+
* Assert that a constraints object is well-formed at schema-construction time.
|
|
83
|
+
*
|
|
84
|
+
* `min` / `max` must be finite — an infinite or `NaN` bound is meaningless (omit
|
|
85
|
+
* the field for "no bound") and would serialize to `null` in the emitted JSON
|
|
86
|
+
* Schema. An inverted range (`min > max`) is also rejected, since it makes the
|
|
87
|
+
* flag/arg permanently unsatisfiable. Throws so the misconfiguration surfaces
|
|
88
|
+
* where the flag/arg is declared, not at parse time.
|
|
89
|
+
*
|
|
90
|
+
* @param constraints - The constraints to validate.
|
|
91
|
+
* @throws RangeError if `min` or `max` is non-finite (`Infinity` / `-Infinity` /
|
|
92
|
+
* `NaN`), or if `min` exceeds `max`.
|
|
93
|
+
*/
|
|
94
|
+
declare function assertNumberConstraints(constraints: NumberConstraints): void;
|
|
95
|
+
//#endregion
|
|
96
|
+
export { DEFAULT_FINITE, type NumberConstraintViolation, type NumberConstraints, assertNumberConstraints, describeNumberConstraintViolation, validateNumberConstraints };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){if(Number.isNaN(e)||(t?.finite??!0)&&!Number.isFinite(e))return{kind:`finite`};if(t?.int===!0&&!Number.isInteger(e))return{kind:`int`};if(t?.min!==void 0&&e<t.min)return{kind:`min`,bound:t.min};if(t?.max!==void 0&&e>t.max)return{kind:`max`,bound:t.max}}function t(e){switch(e.kind){case`finite`:return`must be a finite number`;case`int`:return`must be an integer`;case`min`:return`must be >= ${e.bound}`;case`max`:return`must be <= ${e.bound}`}}function n(e){if(e.min!==void 0&&!Number.isFinite(e.min))throw RangeError(`number constraint 'min' must be a finite number (got ${e.min}); omit it for no lower bound`);if(e.max!==void 0&&!Number.isFinite(e.max))throw RangeError(`number constraint 'max' must be a finite number (got ${e.max}); omit it for no upper bound`);if(e.min!==void 0&&e.max!==void 0&&e.min>e.max)throw RangeError(`number constraint 'min' (${e.min}) must not exceed 'max' (${e.max})`)}export{n as assertNumberConstraints,t as describeNumberConstraintViolation,e as validateNumberConstraints};
|
|
@@ -29,6 +29,12 @@ interface PromptConfigBase {
|
|
|
29
29
|
interface ConfirmPromptConfig extends PromptConfigBase {
|
|
30
30
|
/** Discriminator identifying this as a yes/no confirmation prompt. */
|
|
31
31
|
readonly kind: 'confirm';
|
|
32
|
+
/**
|
|
33
|
+
* Value used when the user submits an empty line (presses Enter). Also
|
|
34
|
+
* drives the displayed hint: `true` → `(Y/n)`, `false` → `(y/N)`.
|
|
35
|
+
* @defaultValue `true`
|
|
36
|
+
*/
|
|
37
|
+
readonly default?: boolean;
|
|
32
38
|
}
|
|
33
39
|
/** Free-text input prompt — maps to `string` and `number` flags. Part of {@link PromptConfig}. */
|
|
34
40
|
interface InputPromptConfig extends PromptConfigBase {
|
|
@@ -36,6 +42,15 @@ interface InputPromptConfig extends PromptConfigBase {
|
|
|
36
42
|
readonly kind: 'input';
|
|
37
43
|
/** Placeholder text shown before user types (informational only). */
|
|
38
44
|
readonly placeholder?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Value used when the user submits an empty line (presses Enter), shown in
|
|
47
|
+
* the hint as `(default: <value>)`. When set, an empty submission resolves
|
|
48
|
+
* to this value without running {@link InputPromptConfig.validate | validate}.
|
|
49
|
+
* When omitted, an empty submission is treated as "no answer" so resolution
|
|
50
|
+
* falls through to the flag's `.default()`.
|
|
51
|
+
* @defaultValue `undefined`
|
|
52
|
+
*/
|
|
53
|
+
readonly default?: string;
|
|
39
54
|
/**
|
|
40
55
|
* Inline validation function. Return `true` if valid, or a string
|
|
41
56
|
* error message if invalid. Called before coercion to flag kind.
|
|
@@ -133,10 +133,10 @@ interface RunOptions {
|
|
|
133
133
|
/**
|
|
134
134
|
* Structured result from {@linkcode runCommand}.
|
|
135
135
|
*
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
* Contains the exit code, captured stdout/stderr output, recorded
|
|
137
|
+
* {@linkcode ActivityEvent | activity events}, and an `error` field.
|
|
138
|
+
* `error` is `undefined` when execution completed without throwing, even if
|
|
139
|
+
* the handler requested a non-zero status via {@linkcode Out.setExitCode}.
|
|
140
140
|
*
|
|
141
141
|
* @example
|
|
142
142
|
* ```ts
|
|
@@ -6,16 +6,20 @@ import { RunnableCommand } from "../schema/command.mjs";
|
|
|
6
6
|
* Run a command builder against the given argv with injected options.
|
|
7
7
|
*
|
|
8
8
|
* This is the testkit wrapper around the shared executor:
|
|
9
|
-
* 1.
|
|
10
|
-
* 2.
|
|
11
|
-
* 3.
|
|
12
|
-
* 4.
|
|
9
|
+
* 1. Apply the CLI root-flag layer (detect/strip `--json`) so copied real argv works
|
|
10
|
+
* 2. Create or reuse capture output
|
|
11
|
+
* 3. Build standalone schema/meta defaults when CLI dispatch did not
|
|
12
|
+
* 4. Delegate parse -> resolve -> execute to the shared executor
|
|
13
|
+
* 5. Return the structured result with captured buffers
|
|
13
14
|
*
|
|
14
15
|
* Errors are normalized by the shared executor into structured {@linkcode RunResult}s
|
|
15
16
|
* with appropriate exit codes. The function never throws.
|
|
16
17
|
*
|
|
17
18
|
* @param cmd - The command builder (must have an action handler)
|
|
18
|
-
* @param argv - Raw argv strings (NOT including the command name itself)
|
|
19
|
+
* @param argv - Raw argv strings (NOT including the command name itself). A
|
|
20
|
+
* CLI-level `--json` before the `--` separator is honored and stripped here,
|
|
21
|
+
* just like the real CLI root — so `['--json']` enables JSON mode rather than
|
|
22
|
+
* failing as an unknown flag. Equivalent to passing `{ jsonMode: true }`.
|
|
19
23
|
* @param options - Injectable runtime state
|
|
20
24
|
* @returns Structured run result with exit code and captured output
|
|
21
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createCaptureOutput as e}from"../output/index.mjs";import{
|
|
1
|
+
import{createCaptureOutput as e}from"../output/index.mjs";import{includesBeforeSeparator as t,stripBeforeSeparator as n}from"../parse/index.mjs";import{buildRunResult as r,executeCommand as i}from"../execution/index.mjs";async function a(a,o,s){let c=t(o,`--json`),l=c||s?.jsonMode===!0,u=c?n(o,`--json`):o,d,f;if(s?.out!==void 0)d=s.out,f=s.captured??{stdout:[],stderr:[],activity:[]};else{let t={...s?.verbosity===void 0?{}:{verbosity:s.verbosity},...l?{jsonMode:l}:{},...s?.isTTY===void 0?{}:{isTTY:s.isTTY}};[d,f]=e(Object.keys(t).length>0?t:void 0)}let p=s?.mergedSchema??a.schema,m=s?.meta??{name:p.name,bin:s?.help?.binName??p.name,version:void 0,command:p.name},h=s===void 0?l?{jsonMode:l}:void 0:{...s,...l?{jsonMode:l}:{}};return r(await i({command:a,argv:u,out:d,schema:p,meta:m,...h===void 0?{}:{options:h}}),f)}export{a as runCommand};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ActivityEvent, Fallback, ProgressHandle, ProgressOptions, SpinnerHandle, SpinnerOptions, TableColumn, TableFormat, TableOptions, TableStream } from "./core/schema/activity.mjs";
|
|
2
|
+
import { NumberConstraintViolation, NumberConstraints } from "./core/schema/number-constraints.mjs";
|
|
2
3
|
import { ArgBuilder, ArgConfig, ArgFactory, ArgKind, ArgParseFn, ArgPresence, ArgSchema, InferArg, InferArgs, ResolvedArgValue, WithArgPresence, WithVariadic, arg, createArgSchema } from "./core/schema/arg.mjs";
|
|
3
4
|
import { ConfirmPromptConfig, InputPromptConfig, MultiselectPromptConfig, PromptConfig, PromptConfigBase, PromptKind, PromptResult, SelectChoice, SelectPromptConfig } from "./core/schema/prompt.mjs";
|
|
4
5
|
import { FlagBuilder, FlagConfig, FlagFactory, FlagKind, FlagParseFn, FlagPresence, FlagSchema, InferFlag, InferFlags, ResolvedValue, WithPresence, createSchema, flag } from "./core/schema/flag.mjs";
|
|
@@ -16,7 +17,7 @@ import { osc8, visibleWidth } from "./core/help/ansi.mjs";
|
|
|
16
17
|
import { HelpOptions, formatHelp } from "./core/help/index.mjs";
|
|
17
18
|
import { RunResult } from "./core/schema/run.mjs";
|
|
18
19
|
import { ActionHandler, ActionParams, AnyCommandBuilder, CommandArgEntry, CommandBuilder, CommandConfig, CommandExample, CommandMeta, CommandSchema, DeriveHandler, DeriveParams, InteractiveParams, InteractiveResolver, InteractiveResult, Out, command, group } from "./core/schema/command.mjs";
|
|
19
|
-
import { PackageJsonAdapter, PackageJsonData, PackageRepository, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
20
|
+
import { ManifestDiscoveryOptions, PackageJsonAdapter, PackageJsonData, PackageRepository, discoverManifest, discoverPackageJson, inferCliName, packageRepositoryUrl } from "./core/config/package-json.mjs";
|
|
20
21
|
import { HelpLinks } from "./core/cli/help-links.mjs";
|
|
21
22
|
import { CompletionOptions } from "./core/completion/shells/shared.mjs";
|
|
22
23
|
import { generateBashCompletion } from "./core/completion/shells/bash.mjs";
|
|
@@ -25,6 +26,6 @@ import { generatePowerShellCompletion } from "./core/completion/shells/powershel
|
|
|
25
26
|
import { generateZshCompletion } from "./core/completion/shells/zsh.mjs";
|
|
26
27
|
import { SHELLS, Shell, generateCompletion } from "./core/completion/index.mjs";
|
|
27
28
|
import { ConfigAdapter, ConfigDiscoveryOptions, ConfigDiscoveryResult, ConfigFound, ConfigNotFound, FormatLoader, buildConfigSearchPaths, configFormat, discoverConfig } from "./core/config/index.mjs";
|
|
28
|
-
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, PackageJsonSettings, cli } from "./core/cli/index.mjs";
|
|
29
|
+
import { CLIBuilder, CLIOptions, CLIRunOptions, CLISchema, ConfigSettings, InferNameOption, ManifestPresetSettings, ManifestSettings, PackageJsonSettings, ResolvedManifestSettings, cli } from "./core/cli/index.mjs";
|
|
29
30
|
import { JsonSchemaOptions, definitionMetaSchema, generateInputSchema, generateSchema } from "./core/json-schema/index.mjs";
|
|
30
|
-
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
|
31
|
+
export { type ActionHandler, type ActionParams, type ActivityEvent, type AnyCommandBuilder, ArgBuilder, type ArgConfig, type ArgFactory, type ArgKind, type ArgParseFn, type ArgPresence, type ArgSchema, type BeforeParseParams, CLIBuilder, CLIError, type CLIErrorJSON, type CLIErrorOptions, type CLIOptions, type CLIPlugin, type CLIPluginHooks, type CLIRunOptions, type CLISchema, type CommandArgEntry, CommandBuilder, type CommandConfig, type CommandExample, type CommandMeta, type CommandSchema, type CompletionOptions, type ConfigAdapter, type ConfigDiscoveryOptions, type ConfigDiscoveryResult, type ConfigFound, type ConfigNotFound, type ConfigSettings, type ConfirmPromptConfig, type DeprecationWarning, type DeriveHandler, type DeriveParams, type ErrorCode, type Fallback, FlagBuilder, type FlagConfig, type FlagFactory, type FlagKind, type FlagParseFn, type FlagPresence, type FlagSchema, type FormatLoader, type HelpLinks, type HelpOptions, type InferArg, type InferArgs, type InferFlag, type InferFlags, type InferNameOption, type InputPromptConfig, type InteractiveParams, type InteractiveResolver, type InteractiveResult, type JsonSchemaOptions, type ManifestDiscoveryOptions, type ManifestPresetSettings, type ManifestSettings, type Middleware, type MiddlewareHandler, type MiddlewareParams, type MultiselectPromptConfig, type NumberConstraintViolation, type NumberConstraints, type Out, type OutputOptions, type PackageJsonAdapter, type PackageJsonData, type PackageJsonSettings, type PackageRepository, ParseError, type ParseErrorCode, type ParseErrorOptions, type ParseResult, type PluginCommandContext, type ProgressHandle, type ProgressOptions, type PromptConfig, type PromptConfigBase, type PromptEngine, type PromptKind, type PromptResult, type ReadFn, type ResolveOptions, type ResolveResult, type ResolvedArgValue, type ResolvedCommandParams, type ResolvedManifestSettings, type ResolvedMultiselectPromptConfig, type ResolvedPromptConfig, type ResolvedSelectPromptConfig, type ResolvedValue, type RunResult, SHELLS, type SelectChoice, type SelectPromptConfig, type Shell, type SpinnerHandle, type SpinnerOptions, type TableColumn, type TableFormat, type TableOptions, type TableStream, type Token, ValidationError, type ValidationErrorCode, type ValidationErrorOptions, type Verbosity, type WithArgPresence, type WithPresence, type WithVariadic, type WriteFn, arg, buildConfigSearchPaths, cli, command, configFormat, createArgSchema, createOutput, createSchema, createTerminalPrompter, definitionMetaSchema, discoverConfig, discoverManifest, discoverPackageJson, flag, formatHelp, generateBashCompletion, generateCompletion, generateFishCompletion, generateInputSchema, generatePowerShellCompletion, generateSchema, generateZshCompletion, group, inferCliName, isCLIError, isParseError, isValidationError, middleware, osc8, packageRepositoryUrl, parse, plugin, resolve, resolvePromptConfig, tokenize, visibleWidth };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FlagBuilder as e,createSchema as t,flag as n}from"./core/schema/flag.mjs";import{generateBashCompletion as r}from"./core/completion/shells/bash.mjs";import{generateFishCompletion as i}from"./core/completion/shells/fish.mjs";import{generatePowerShellCompletion as a}from"./core/completion/shells/powershell.mjs";import{CLIError as o,ParseError as s,ValidationError as c,isCLIError as l,isParseError as u,isValidationError as d}from"./core/errors/index.mjs";import{generateZshCompletion as f}from"./core/completion/shells/zsh.mjs";import{SHELLS as p,generateCompletion as m}from"./core/completion/index.mjs";import{osc8 as h,visibleWidth as g}from"./core/help/ansi.mjs";import{formatHelp as _}from"./core/help/index.mjs";import{createOutput as v}from"./core/output/index.mjs";import{
|
|
1
|
+
import{FlagBuilder as e,createSchema as t,flag as n}from"./core/schema/flag.mjs";import{generateBashCompletion as r}from"./core/completion/shells/bash.mjs";import{generateFishCompletion as i}from"./core/completion/shells/fish.mjs";import{generatePowerShellCompletion as a}from"./core/completion/shells/powershell.mjs";import{CLIError as o,ParseError as s,ValidationError as c,isCLIError as l,isParseError as u,isValidationError as d}from"./core/errors/index.mjs";import{generateZshCompletion as f}from"./core/completion/shells/zsh.mjs";import{SHELLS as p,generateCompletion as m}from"./core/completion/index.mjs";import{osc8 as h,visibleWidth as g}from"./core/help/ansi.mjs";import{formatHelp as _}from"./core/help/index.mjs";import{createOutput as v}from"./core/output/index.mjs";import{ArgBuilder as y,arg as b,createArgSchema as x}from"./core/schema/arg.mjs";import{CommandBuilder as S,command as C,group as w}from"./core/schema/command.mjs";import{middleware as T}from"./core/schema/middleware.mjs";import{parse as E,tokenize as D}from"./core/parse/index.mjs";import{createTerminalPrompter as O,resolvePromptConfig as k}from"./core/prompt/index.mjs";import{resolve as A}from"./core/resolve/index.mjs";import{discoverManifest as j,discoverPackageJson as M,inferCliName as N,packageRepositoryUrl as P}from"./core/config/package-json.mjs";import{plugin as F}from"./core/cli/plugin.mjs";import{buildConfigSearchPaths as I,configFormat as L,discoverConfig as R}from"./core/config/index.mjs";import{CLIBuilder as z,cli as B}from"./core/cli/index.mjs";import{definitionMetaSchema as V,generateInputSchema as H,generateSchema as U}from"./core/json-schema/index.mjs";export{y as ArgBuilder,z as CLIBuilder,o as CLIError,S as CommandBuilder,e as FlagBuilder,s as ParseError,p as SHELLS,c as ValidationError,b as arg,I as buildConfigSearchPaths,B as cli,C as command,L as configFormat,x as createArgSchema,v as createOutput,t as createSchema,O as createTerminalPrompter,V as definitionMetaSchema,R as discoverConfig,j as discoverManifest,M as discoverPackageJson,n as flag,_ as formatHelp,r as generateBashCompletion,m as generateCompletion,i as generateFishCompletion,H as generateInputSchema,a as generatePowerShellCompletion,U as generateSchema,f as generateZshCompletion,w as group,N as inferCliName,l as isCLIError,u as isParseError,d as isValidationError,T as middleware,h as osc8,P as packageRepositoryUrl,E as parse,F as plugin,A as resolve,k as resolvePromptConfig,D as tokenize,g as visibleWidth};
|
package/dist/runtime/auto.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createNodeAdapter as e}from"./node.mjs";import{createBunAdapter as t}from"./bun.mjs";import{createDenoAdapter as n}from"./deno.mjs";import{detectRuntime as r}from"./detect.mjs";function i(e){if(typeof e!=`object`||!e)return!1;let t=e;return Array.isArray(t.args)&&typeof t.cwd==`function`&&typeof t.exit==`function`&&typeof t.readTextFile==`function`&&typeof t.env?.get==`function`&&typeof t.env.toObject==`function`&&typeof t.stdout?.writeSync==`function`&&typeof t.stdout.isTerminal==`function`&&typeof t.stderr?.writeSync==`function`&&typeof t.stdin?.isTerminal==`function`&&typeof t.stdin?.readable?.getReader==`function`}function a(e){let t=e.Deno;return i(t)?t:void 0}function o(i){let o=i??globalThis,s=r(o);switch(s){case`bun`:return t();case`deno`:return n(a(o));case`node`:case`unknown`:return e();default:return s}}export{o as createAdapter};
|
package/dist/runtime/bun.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createNodeAdapter as e}from"./node.mjs";function t(t){return e(t)}export{t as createBunAdapter};
|
package/dist/runtime/deno.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";
|
|
2
|
-
`);if(e!==-1){let t=n.slice(0,e).replace(/\r$/,``);return n=n.slice(e+1),t}if(r){if(n.length===0)return null;let e=n;return n=``,e}let{value:a,done:o}=await i.read();if(o){n+=t.decode(),r=!0;continue}n+=t.decode(a,{stream:!0})}}finally{i.releaseLock()}}}function
|
|
1
|
+
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";function n(e,t){if(typeof e!=`object`||!e||!(`name`in e))return!1;let n=e;return typeof n.name==`string`&&n.name===t}function r(e){try{return e.env.toObject()}catch(e){if(n(e,`PermissionDenied`))return{};throw e}}function i(e){try{return e.cwd()}catch(e){if(n(e,`PermissionDenied`))return`/`;throw e}}function a(e){let t=e??o(),a=new TextEncoder,d=[`deno`,`run`,...t.args],f=r(t),p=i(t),m=e=>{t.stdout.writeSync(a.encode(e))},h=e=>{t.stderr.writeSync(a.encode(e))},g=c(t),_=async e=>{try{return await t.readTextFile(e)}catch(e){if(n(e,`NotFound`)||n(e,`PermissionDenied`))return null;throw e}},v=l(f,t.build.os===`windows`),y=u(f,v,t.build.os===`windows`),b=t.stdin.isTerminal();return{argv:d,env:f,cwd:p,stdout:m,stderr:h,stdin:g,readStdin:()=>s(t,b),isTTY:t.stdout.isTerminal(),stdinIsTTY:b,exit:e=>t.exit(e),readFile:_,homedir:v,configDir:y}}function o(){return globalThis.Deno}async function s(e,t){if(t)return null;let n=e.stdin.readable.getReader(),r=new TextDecoder,i=[];try{for(;;){let{value:e,done:t}=await n.read();if(t){i.push(r.decode());break}i.push(r.decode(e,{stream:!0}))}}finally{n.releaseLock()}return i.join(``)}function c(e){let t=new TextDecoder,n=``,r=!1;return async()=>{let i=e.stdin.readable.getReader();try{for(;;){let e=n.indexOf(`
|
|
2
|
+
`);if(e!==-1){let t=n.slice(0,e).replace(/\r$/,``);return n=n.slice(e+1),t}if(r){if(n.length===0)return null;let e=n;return n=``,e}let{value:a,done:o}=await i.read();if(o){n+=t.decode(),r=!0;continue}n+=t.decode(a,{stream:!0})}}finally{i.releaseLock()}}}function l(e,n){return t(e,n)}function u(t,n,r){return e(t,r,n)}export{a as createDenoAdapter};
|
package/dist/runtime/node.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";
|
|
2
|
-
`);if(e!==-1){let t=r.slice(0,e).replace(/\r$/,``);return r=r.slice(e+1),t}if(i){if(r.length===0)return null;let e=r;return r=``,e}let a=await t.next();if(a.done){r+=n.decode(),i=!0;continue}r+=n.decode(a.value,{stream:!0})}}}export{
|
|
1
|
+
import{resolveConfigDirectory as e,resolveHomeDirectory as t}from"./paths.mjs";function n(){return globalThis.process}function r(e){return typeof e!=`object`||!e||!(`code`in e)?!1:typeof e.code==`string`}function i(e,n){return t(e,n===`win32`)}function a(t,n,r){return e(t,n===`win32`,r)}function o(e){let t=e??n(),o=e=>{t.stdout.write(e)},l=e=>{t.stderr.write(e)},u=c(t),d=async e=>{let t=await import(`node:fs/promises`);try{return await t.readFile(e,`utf8`)}catch(e){if(r(e)&&e.code===`ENOENT`)return null;throw e}},f=i(t.env,t.platform),p=a(t.env,t.platform,f),m=t.stdin.isTTY===!0;return{argv:t.argv,env:t.env,cwd:t.cwd(),stdout:o,stderr:l,stdin:u,readStdin:()=>s(t,m),isTTY:t.stdout.isTTY===!0,stdinIsTTY:m,exit:e=>t.exit(e),readFile:d,homedir:f,configDir:p}}async function s(e,t){if(t)return null;let n=[],r=new TextDecoder;for await(let t of e.stdin)n.push(r.decode(t,{stream:!0}));return n.push(r.decode()),n.join(``)}function c(e){let t=e.stdin[Symbol.asyncIterator](),n=new TextDecoder,r=``,i=!1;return async()=>{for(;;){let e=r.indexOf(`
|
|
2
|
+
`);if(e!==-1){let t=r.slice(0,e).replace(/\r$/,``);return r=r.slice(e+1),t}if(i){if(r.length===0)return null;let e=r;return r=``,e}let a=await t.next();if(a.done){r+=n.decode(),i=!0;continue}r+=n.decode(a.value,{stream:!0})}}}export{o as createNodeAdapter};
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`
|
|
1
|
+
const e=`3.0.0-rc.1`,t=`c3bcd04`;export{t as DREAMCLI_REVISION,e as DREAMCLI_VERSION};
|
package/examples/basic.ts
CHANGED
|
@@ -24,7 +24,11 @@ const greet = command('greet')
|
|
|
24
24
|
// args.name: string — required positional
|
|
25
25
|
// flags.loud: boolean — defaults to false (all booleans do)
|
|
26
26
|
// flags.times: number — defaults to 1 (never undefined)
|
|
27
|
-
|
|
27
|
+
const repeatCount = Number.isFinite(flags.times)
|
|
28
|
+
? Math.max(0, Math.min(100, Math.floor(flags.times)))
|
|
29
|
+
: 1;
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < repeatCount; i++) {
|
|
28
32
|
const msg = `Hello, ${args.name}!`;
|
|
29
33
|
out.log(flags.loud ? msg.toUpperCase() : msg);
|
|
30
34
|
}
|
package/examples/gh/package.json
CHANGED
|
@@ -10,13 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"module": "src/main.ts",
|
|
13
|
-
"bin":
|
|
14
|
-
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"src",
|
|
18
|
-
"!src/**/*.test.ts"
|
|
19
|
-
],
|
|
13
|
+
"bin": "src/main.ts",
|
|
14
|
+
"files": ["src", "!src/**/*.test.ts"],
|
|
20
15
|
"scripts": {
|
|
21
16
|
"bd": "bun run build",
|
|
22
17
|
"build": "bun build src/main.ts --install --outdir=dist --format=esm --target=node --external @kjanat/dreamcli",
|
|
@@ -13,13 +13,7 @@
|
|
|
13
13
|
"bin": {
|
|
14
14
|
"pwsh-demo": "src/main.ts"
|
|
15
15
|
},
|
|
16
|
-
"files": [
|
|
17
|
-
"src",
|
|
18
|
-
"README.md",
|
|
19
|
-
"smoke-powershell.ps1",
|
|
20
|
-
"pwsh-demo.cmd",
|
|
21
|
-
"!src/**/*.test.ts"
|
|
22
|
-
],
|
|
16
|
+
"files": ["src", "README.md", "smoke-powershell.ps1", "pwsh-demo.cmd", "!src/**/*.test.ts"],
|
|
23
17
|
"scripts": {
|
|
24
18
|
"build": "bun build src/main.ts --install --outdir=dist --format=esm --target=node --external @kjanat/dreamcli",
|
|
25
19
|
"smoke:powershell": "pwsh -NoLogo -NoProfile -ExecutionPolicy Bypass -File ./smoke-powershell.ps1",
|
|
@@ -40,9 +40,6 @@ describe('pwsh-demo example', () => {
|
|
|
40
40
|
const result = await pwshDemo.execute(['bravo', '--profile', 'ops', '--shell', 'cmd']);
|
|
41
41
|
|
|
42
42
|
expect(result.exitCode).toBe(0);
|
|
43
|
-
expect(result.stdout).toEqual([
|
|
44
|
-
'Opening bravo with ops profile in cmd\n',
|
|
45
|
-
'Format: table\n',
|
|
46
|
-
]);
|
|
43
|
+
expect(result.stdout).toEqual(['Opening bravo with ops profile in cmd\n', 'Format: table\n']);
|
|
47
44
|
});
|
|
48
45
|
});
|
|
@@ -35,7 +35,9 @@ const open = command('open')
|
|
|
35
35
|
.flag('format', flag.enum(['table', 'json', 'yaml']).alias('f').describe('Output format'))
|
|
36
36
|
.flag('verbose', flag.boolean().alias('v').describe('Verbose logging'))
|
|
37
37
|
.action(({ args, flags, out }) => {
|
|
38
|
-
out.log(
|
|
38
|
+
out.log(
|
|
39
|
+
`Opening ${args.workspace} with ${flags.profile ?? 'default'} profile in ${flags.shell}`,
|
|
40
|
+
);
|
|
39
41
|
out.log(`Format: ${flags.format ?? 'table'}`);
|
|
40
42
|
if (flags.verbose) out.log('Verbose output enabled');
|
|
41
43
|
});
|
|
@@ -55,7 +57,9 @@ const deploy = command('deploy')
|
|
|
55
57
|
.flag('approval', flag.enum(['manual', 'auto']).describe('Approval mode'))
|
|
56
58
|
.flag('dryRun', flag.boolean().alias('d').describe('Preview the rollout without applying it'))
|
|
57
59
|
.action(({ args, flags, out }) => {
|
|
58
|
-
out.log(
|
|
60
|
+
out.log(
|
|
61
|
+
`Deploying ${args.target} to ${flags.region ?? 'us'} with ${flags.strategy ?? 'rolling'}`,
|
|
62
|
+
);
|
|
59
63
|
out.log(`Approval: ${flags.approval ?? 'manual'}`);
|
|
60
64
|
if (flags.dryRun) out.log('Dry run only');
|
|
61
65
|
});
|
|
@@ -82,7 +86,10 @@ const configSet = command('set')
|
|
|
82
86
|
.description('Write a saved setting')
|
|
83
87
|
.arg('key', arg.enum(['theme', 'region', 'profile']).describe('Setting to write'))
|
|
84
88
|
.arg('value', arg.string().describe('New value'))
|
|
85
|
-
.flag(
|
|
89
|
+
.flag(
|
|
90
|
+
'scope',
|
|
91
|
+
flag.enum(['user', 'workspace']).alias('s').default('user').describe('Config scope'),
|
|
92
|
+
)
|
|
86
93
|
.action(({ args, flags, out }) => {
|
|
87
94
|
out.log(`Saved ${args.key}=${args.value} to ${flags.scope} scope`);
|
|
88
95
|
});
|
|
@@ -107,7 +114,10 @@ const debugDump = command('debug-dump')
|
|
|
107
114
|
.hidden()
|
|
108
115
|
.flag(
|
|
109
116
|
'section',
|
|
110
|
-
flag
|
|
117
|
+
flag
|
|
118
|
+
.enum(['schema', 'completions', 'runtime'])
|
|
119
|
+
.default('schema')
|
|
120
|
+
.describe('Section to inspect'),
|
|
111
121
|
)
|
|
112
122
|
.action(({ flags, out }) => {
|
|
113
123
|
out.log(JSON.stringify({ section: flags.section, hidden: true }, null, 2));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Single-transport launcher (language-server style).
|
|
4
|
+
*
|
|
5
|
+
* A launcher that must be started over exactly one transport. dreamcli has no
|
|
6
|
+
* native "mutually exclusive" / "exactly one of" modifier, so the rule is
|
|
7
|
+
* expressed in `.derive()` — the resolution-time hook that runs after flags
|
|
8
|
+
* resolve and before the action. The derived, fully typed `Transport` is then
|
|
9
|
+
* handed to `.action()` through `ctx`.
|
|
10
|
+
*
|
|
11
|
+
* Demonstrates: an "exactly one of" rule via `.derive()` throwing `CLIError`, a
|
|
12
|
+
* kebab-case flag name accessed with bracket notation (`flags['node-ipc']`), and
|
|
13
|
+
* passing a typed result to the action through derived context.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* npx tsx examples/transport-launcher.ts --stdio
|
|
17
|
+
* npx tsx examples/transport-launcher.ts --node-ipc
|
|
18
|
+
* npx tsx examples/transport-launcher.ts --socket 6009
|
|
19
|
+
* npx tsx examples/transport-launcher.ts # error: pick exactly one
|
|
20
|
+
* npx tsx examples/transport-launcher.ts --stdio --node-ipc # error: only one
|
|
21
|
+
* npx tsx examples/transport-launcher.ts --help
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { CLIError, cli, command, flag } from '@kjanat/dreamcli';
|
|
25
|
+
|
|
26
|
+
// One resolved transport — illegal states are unrepresentable.
|
|
27
|
+
type Transport =
|
|
28
|
+
| { readonly kind: 'stdio' }
|
|
29
|
+
| { readonly kind: 'node-ipc' }
|
|
30
|
+
| { readonly kind: 'socket'; readonly port: number };
|
|
31
|
+
|
|
32
|
+
const launcher = command('lsp-server')
|
|
33
|
+
.description('Launch the language server over exactly one transport')
|
|
34
|
+
.flag('stdio', flag.boolean().describe('Use the stdio transport'))
|
|
35
|
+
.flag('node-ipc', flag.boolean().describe('Use the Node IPC transport'))
|
|
36
|
+
.flag('socket', flag.number().describe('Use a TCP socket on <port>'))
|
|
37
|
+
// `.derive()` runs after resolution and before the action — the idiomatic
|
|
38
|
+
// place for a constraint dreamcli does not express declaratively.
|
|
39
|
+
.derive(({ flags }): { transport: Transport } => {
|
|
40
|
+
const selected: Transport[] = [];
|
|
41
|
+
if (flags.stdio) selected.push({ kind: 'stdio' });
|
|
42
|
+
// Kebab-case flag names stay kebab in the handler: bracket access, no camelCasing.
|
|
43
|
+
if (flags['node-ipc']) selected.push({ kind: 'node-ipc' });
|
|
44
|
+
if (flags.socket !== undefined) {
|
|
45
|
+
if (!Number.isInteger(flags.socket)) {
|
|
46
|
+
throw new CLIError(`--socket expects an integer port (got ${flags.socket}).`, {
|
|
47
|
+
code: 'INVALID_SOCKET_PORT',
|
|
48
|
+
suggest: 'Pass a whole number, e.g. --socket 6009',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
selected.push({ kind: 'socket', port: flags.socket });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const [transport, ...rest] = selected;
|
|
55
|
+
if (transport === undefined) {
|
|
56
|
+
throw new CLIError('No transport selected.', {
|
|
57
|
+
code: 'NO_TRANSPORT',
|
|
58
|
+
suggest: 'Pass exactly one of --stdio, --node-ipc, or --socket <port>',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (rest.length > 0) {
|
|
62
|
+
throw new CLIError('Choose exactly one transport flag.', {
|
|
63
|
+
code: 'TOO_MANY_TRANSPORTS',
|
|
64
|
+
suggest: 'Use only one of --stdio, --node-ipc, or --socket <port>',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { transport };
|
|
69
|
+
})
|
|
70
|
+
.action(({ ctx, out }) => {
|
|
71
|
+
// ctx.transport: Transport — fully typed, ready to hand to the server.
|
|
72
|
+
switch (ctx.transport.kind) {
|
|
73
|
+
case 'stdio':
|
|
74
|
+
out.log('Starting language server over stdio');
|
|
75
|
+
break;
|
|
76
|
+
case 'node-ipc':
|
|
77
|
+
out.log('Starting language server over node-ipc');
|
|
78
|
+
break;
|
|
79
|
+
case 'socket':
|
|
80
|
+
out.log(`Starting language server over socket :${ctx.transport.port}`);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
void cli('lsp-server').default(launcher).run();
|