@ontrails/cli 1.0.0-beta.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/.turbo/turbo-build.log +1 -0
- package/.turbo/turbo-lint.log +3 -0
- package/.turbo/turbo-typecheck.log +1 -0
- package/CHANGELOG.md +20 -0
- package/README.md +166 -0
- package/dist/build.d.ts +25 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +167 -0
- package/dist/build.js.map +1 -0
- package/dist/command.d.ts +47 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +9 -0
- package/dist/command.js.map +1 -0
- package/dist/commander/blaze.d.ts +31 -0
- package/dist/commander/blaze.d.ts.map +1 -0
- package/dist/commander/blaze.js +42 -0
- package/dist/commander/blaze.js.map +1 -0
- package/dist/commander/index.d.ts +5 -0
- package/dist/commander/index.d.ts.map +1 -0
- package/dist/commander/index.js +3 -0
- package/dist/commander/index.js.map +1 -0
- package/dist/commander/to-commander.d.ts +12 -0
- package/dist/commander/to-commander.d.ts.map +1 -0
- package/dist/commander/to-commander.js +148 -0
- package/dist/commander/to-commander.js.map +1 -0
- package/dist/flags.d.ts +17 -0
- package/dist/flags.d.ts.map +1 -0
- package/dist/flags.js +180 -0
- package/dist/flags.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/layers.d.ts +21 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +156 -0
- package/dist/layers.js.map +1 -0
- package/dist/on-result.d.ts +12 -0
- package/dist/on-result.d.ts.map +1 -0
- package/dist/on-result.js +21 -0
- package/dist/on-result.js.map +1 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +82 -0
- package/dist/output.js.map +1 -0
- package/dist/prompt.d.ts +29 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +12 -0
- package/dist/prompt.js.map +1 -0
- package/package.json +29 -0
- package/src/__tests__/blaze.test.ts +78 -0
- package/src/__tests__/build.test.ts +219 -0
- package/src/__tests__/flags.test.ts +176 -0
- package/src/__tests__/layers.test.ts +218 -0
- package/src/__tests__/on-result.test.ts +64 -0
- package/src/__tests__/output.test.ts +115 -0
- package/src/__tests__/to-commander.test.ts +133 -0
- package/src/build.ts +267 -0
- package/src/command.ts +73 -0
- package/src/commander/blaze.ts +67 -0
- package/src/commander/index.ts +5 -0
- package/src/commander/to-commander.ts +186 -0
- package/src/flags.ts +250 -0
- package/src/index.ts +28 -0
- package/src/layers.ts +231 -0
- package/src/on-result.ts +27 -0
- package/src/output.ts +101 -0
- package/src/prompt.ts +40 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc -b
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
$ tsc --noEmit
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @ontrails/cli
|
|
2
|
+
|
|
3
|
+
## 1.0.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Initial v1 beta release of the Trails framework.
|
|
8
|
+
|
|
9
|
+
- **@ontrails/core** — Result type, error taxonomy, trail/hike/event/topo, validateTopo, validateInput/Output, deriveFields, patterns, redaction, branded types, resilience
|
|
10
|
+
- **@ontrails/cli** — CLI surface adapter, Commander integration, flag derivation, layers
|
|
11
|
+
- **@ontrails/mcp** — MCP surface adapter, tool generation, annotations, progress bridge
|
|
12
|
+
- **@ontrails/logging** — Structured logging, sinks, formatters, LogTape adapter
|
|
13
|
+
- **@ontrails/testing** — testAll, testExamples, testTrail, testHike, testContracts, testDetours, surface harnesses
|
|
14
|
+
- **@ontrails/warden** — AST-based code convention rules via oxc-parser, drift detection, CI formatters
|
|
15
|
+
- **@ontrails/schema** — Surface map generation, hashing, semantic diffing
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
- @ontrails/core@1.0.0-beta.0
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @ontrails/cli
|
|
2
|
+
|
|
3
|
+
CLI surface adapter for Trails. Framework-agnostic command model, automatic flag derivation from Zod schemas, output formatting, and a Commander adapter with a one-line `blaze()` entry point.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @ontrails/cli
|
|
9
|
+
# If using the /commander subpath:
|
|
10
|
+
bun add commander
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`commander` is an optional peer dependency -- only required if you use the `/commander` subpath. The main `@ontrails/cli` export is framework-agnostic.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { trail, topo, Result } from '@ontrails/core';
|
|
19
|
+
import { blaze } from '@ontrails/cli/commander';
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
|
|
22
|
+
const greet = trail('greet', {
|
|
23
|
+
input: z.object({ name: z.string().describe('Who to greet') }),
|
|
24
|
+
implementation: (input) => Result.ok(`Hello, ${input.name}!`),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const app = topo('myapp', { greet });
|
|
28
|
+
blaze(app);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Pure trails can return `Result` directly. The CLI surface still runs the normalized awaitable implementation shape at execution time.
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
$ myapp greet --name World
|
|
35
|
+
Hello, World!
|
|
36
|
+
|
|
37
|
+
$ myapp greet --help
|
|
38
|
+
Usage: myapp greet [options]
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
--name <value> Who to greet
|
|
42
|
+
-h, --help display help for command
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API Overview
|
|
46
|
+
|
|
47
|
+
### `blaze(app, options?)` -- Commander Adapter
|
|
48
|
+
|
|
49
|
+
The one-liner. Builds commands from the topo, adapts to Commander, parses `process.argv`.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { blaze } from '@ontrails/cli/commander';
|
|
53
|
+
|
|
54
|
+
blaze(app, {
|
|
55
|
+
name: 'myapp',
|
|
56
|
+
version: '1.0.0',
|
|
57
|
+
onResult: async (ctx) => {
|
|
58
|
+
/* custom result handling */
|
|
59
|
+
},
|
|
60
|
+
layers: [myAuthLayer],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `buildCliCommands(app, options?)`
|
|
65
|
+
|
|
66
|
+
Framework-agnostic command builder. Produces `CliCommand[]` that any CLI framework can consume.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { buildCliCommands } from '@ontrails/cli';
|
|
70
|
+
|
|
71
|
+
const commands = buildCliCommands(app);
|
|
72
|
+
// Each command: name, flags, args, group, trail ref, execute()
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Flag Derivation
|
|
76
|
+
|
|
77
|
+
Flags are derived automatically from the trail's Zod input schema:
|
|
78
|
+
|
|
79
|
+
| Zod type | CLI flag | Notes |
|
|
80
|
+
| --------------------- | ------------------- | ----------------------------- |
|
|
81
|
+
| `z.string()` | `--name <value>` | Required string |
|
|
82
|
+
| `z.number()` | `--count <value>` | Required number |
|
|
83
|
+
| `z.boolean()` | `--verbose` | Boolean switch |
|
|
84
|
+
| `z.enum(["a", "b"])` | `--format <value>` | With choices |
|
|
85
|
+
| `z.array(z.string())` | `--tag <values...>` | Repeatable: `--tag a --tag b` |
|
|
86
|
+
| `z.optional(...)` | `--name [value]` | Optional |
|
|
87
|
+
| `z.default(...)` | `--name [value]` | With default value |
|
|
88
|
+
|
|
89
|
+
Name conversion: `camelCase` field names become `--kebab-case` flags. `.describe()` on Zod fields becomes help text.
|
|
90
|
+
|
|
91
|
+
### Trail ID to Command Mapping
|
|
92
|
+
|
|
93
|
+
Dotted trail IDs create subcommand groups:
|
|
94
|
+
|
|
95
|
+
| Trail ID | CLI command |
|
|
96
|
+
| ------------- | ------------------- |
|
|
97
|
+
| `greet` | `myapp greet` |
|
|
98
|
+
| `entity.show` | `myapp entity show` |
|
|
99
|
+
| `math.add` | `myapp math add` |
|
|
100
|
+
|
|
101
|
+
### Output Formatting
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { output, resolveOutputMode } from '@ontrails/cli';
|
|
105
|
+
|
|
106
|
+
await output({ name: 'Alpha' }, 'json'); // Pretty JSON
|
|
107
|
+
await output(items, 'jsonl'); // One JSON line per item
|
|
108
|
+
await output('Hello', 'text'); // Plain text
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Output mode resolution priority: `--json` > `--jsonl` > `--output <mode>` > `TRAILS_JSON=1` > `TRAILS_JSONL=1` > `"text"`.
|
|
112
|
+
|
|
113
|
+
### Flag Presets
|
|
114
|
+
|
|
115
|
+
- **`outputModePreset()`** -- `--output <mode>`, `--json`, `--jsonl`
|
|
116
|
+
- **`cwdPreset()`** -- `--cwd <path>`
|
|
117
|
+
- **`dryRunPreset()`** -- `--dry-run` (auto-added for destructive trails)
|
|
118
|
+
|
|
119
|
+
### Built-in Layers
|
|
120
|
+
|
|
121
|
+
- **`autoIterateLayer`** -- Adds `--all` flag for paginated trails; collects all pages.
|
|
122
|
+
- **`dateShortcutsLayer`** -- Expands `"today"`, `"7d"`, `"30d"`, `"this-week"`, `"this-month"` into ISO date ranges.
|
|
123
|
+
|
|
124
|
+
### Commander Adapter (Advanced)
|
|
125
|
+
|
|
126
|
+
Build the Commander program manually for full control:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { buildCliCommands } from '@ontrails/cli';
|
|
130
|
+
import { toCommander } from '@ontrails/cli/commander';
|
|
131
|
+
|
|
132
|
+
const commands = buildCliCommands(app);
|
|
133
|
+
const program = toCommander(commands, { name: 'myapp' });
|
|
134
|
+
program.parse();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
To use a different CLI framework, consume `CliCommand[]` and write your own adapter.
|
|
138
|
+
|
|
139
|
+
### Error Handling
|
|
140
|
+
|
|
141
|
+
Trail error categories map to exit codes automatically:
|
|
142
|
+
|
|
143
|
+
| Category | Exit code |
|
|
144
|
+
| ------------ | --------- |
|
|
145
|
+
| `validation` | 1 |
|
|
146
|
+
| `not_found` | 2 |
|
|
147
|
+
| `conflict` | 3 |
|
|
148
|
+
| `permission` | 4 |
|
|
149
|
+
| `timeout` | 5 |
|
|
150
|
+
| `rate_limit` | 6 |
|
|
151
|
+
| `network` | 7 |
|
|
152
|
+
| `internal` | 8 |
|
|
153
|
+
| `auth` | 9 |
|
|
154
|
+
| `cancelled` | 130 |
|
|
155
|
+
|
|
156
|
+
## Subpath Exports
|
|
157
|
+
|
|
158
|
+
| Export | Contents |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| `@ontrails/cli` | `buildCliCommands`, `deriveFlags`, `output`, `resolveOutputMode`, flag presets, layers, `CliCommand` types |
|
|
161
|
+
| `@ontrails/cli/commander` | `toCommander`, `blaze` (requires `commander` peer) |
|
|
162
|
+
|
|
163
|
+
## Further Reading
|
|
164
|
+
|
|
165
|
+
- [CLI Surface Guide](../../docs/surfaces/cli.md)
|
|
166
|
+
- [Getting Started](../../docs/getting-started.md)
|
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build framework-agnostic CliCommand[] from an App's topology.
|
|
3
|
+
*/
|
|
4
|
+
import type { Layer, Topo, TrailContext } from '@ontrails/core';
|
|
5
|
+
import { Result } from '@ontrails/core';
|
|
6
|
+
import type { AnyTrail, CliCommand, CliFlag } from './command.js';
|
|
7
|
+
import type { InputResolver } from './prompt.js';
|
|
8
|
+
/** Context passed to the onResult callback. */
|
|
9
|
+
export interface ActionResultContext {
|
|
10
|
+
readonly args: Record<string, unknown>;
|
|
11
|
+
readonly flags: Record<string, unknown>;
|
|
12
|
+
readonly input: unknown;
|
|
13
|
+
readonly result: Result<unknown, Error>;
|
|
14
|
+
readonly trail: AnyTrail;
|
|
15
|
+
}
|
|
16
|
+
/** Options for buildCliCommands. */
|
|
17
|
+
export interface BuildCliCommandsOptions {
|
|
18
|
+
createContext?: (() => TrailContext | Promise<TrailContext>) | undefined;
|
|
19
|
+
layers?: Layer[] | undefined;
|
|
20
|
+
onResult?: ((ctx: ActionResultContext) => Promise<void>) | undefined;
|
|
21
|
+
presets?: CliFlag[][] | undefined;
|
|
22
|
+
resolveInput?: InputResolver | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare const buildCliCommands: (app: Topo, options?: BuildCliCommandsOptions) => CliCommand[];
|
|
25
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAS,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CAC1B;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,aAAa,CAAC,EAAE,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC;IACzE,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IAC7B,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IACrE,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,SAAS,CAAC;IAClC,YAAY,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC1C;AAiND,eAAO,MAAM,gBAAgB,GAC3B,KAAK,IAAI,EACT,UAAU,uBAAuB,KAChC,UAAU,EAiBZ,CAAC"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build framework-agnostic CliCommand[] from an App's topology.
|
|
3
|
+
*/
|
|
4
|
+
import { Result, composeLayers, createTrailContext, deriveFields, validateInput, } from '@ontrails/core';
|
|
5
|
+
import { dryRunPreset, toFlags } from './flags.js';
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Helpers
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
/** Convert kebab-case flag name back to camelCase for input merging. */
|
|
10
|
+
const toCamel = (str) => str.replaceAll(/-([a-z])/g, (_, ch) => ch.toUpperCase());
|
|
11
|
+
/**
|
|
12
|
+
* Parse a trail ID into group + command name.
|
|
13
|
+
* "entity.show" -> { group: "entity", name: "show" }
|
|
14
|
+
* "search" -> { group: undefined, name: "search" }
|
|
15
|
+
*/
|
|
16
|
+
const parseTrailId = (id) => {
|
|
17
|
+
const dotIndex = id.indexOf('.');
|
|
18
|
+
if (dotIndex === -1) {
|
|
19
|
+
return { group: undefined, name: id };
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
group: id.slice(0, dotIndex),
|
|
23
|
+
name: id.slice(dotIndex + 1),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Merge preset flags with schema-derived flags.
|
|
28
|
+
* Schema-derived flags take precedence on name collision.
|
|
29
|
+
*/
|
|
30
|
+
const mergeFlags = (presets, derived) => {
|
|
31
|
+
const derivedNames = new Set(derived.map((f) => f.name));
|
|
32
|
+
const merged = [...derived];
|
|
33
|
+
for (const preset of presets) {
|
|
34
|
+
if (!derivedNames.has(preset.name)) {
|
|
35
|
+
merged.push(preset);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return merged;
|
|
39
|
+
};
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// buildCliCommands
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
/**
|
|
44
|
+
* Build an array of framework-agnostic CLI commands from an App.
|
|
45
|
+
*
|
|
46
|
+
* Iterates the topo, derives flags from input schemas, groups by
|
|
47
|
+
* dot-notation, and wires up the execute function with validation,
|
|
48
|
+
* layer composition, and onResult handling.
|
|
49
|
+
*/
|
|
50
|
+
const META_FLAGS = new Set(['json', 'jsonl', 'output']);
|
|
51
|
+
/** Merge parsed args and flags into a camelCase input record. */
|
|
52
|
+
const mergeArgsAndFlags = (parsedArgs, parsedFlags) => {
|
|
53
|
+
const mergedInput = { ...parsedArgs };
|
|
54
|
+
for (const [key, value] of Object.entries(parsedFlags)) {
|
|
55
|
+
if (!META_FLAGS.has(key)) {
|
|
56
|
+
mergedInput[toCamel(key)] = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return mergedInput;
|
|
60
|
+
};
|
|
61
|
+
/** Apply interactive prompting and merge results. */
|
|
62
|
+
const applyPrompting = async (fields, mergedInput, options) => {
|
|
63
|
+
if (!options?.resolveInput) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const resolved = await options.resolveInput(fields, mergedInput);
|
|
67
|
+
for (const [key, value] of Object.entries(resolved)) {
|
|
68
|
+
if (value !== undefined) {
|
|
69
|
+
mergedInput[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** Resolve a TrailContext from overrides, factory, or default. */
|
|
74
|
+
const resolveContext = (ctxOverrides, options) => {
|
|
75
|
+
if (ctxOverrides) {
|
|
76
|
+
return Promise.resolve(createTrailContext(ctxOverrides));
|
|
77
|
+
}
|
|
78
|
+
if (options?.createContext) {
|
|
79
|
+
return Promise.resolve(options.createContext());
|
|
80
|
+
}
|
|
81
|
+
return Promise.resolve(createTrailContext());
|
|
82
|
+
};
|
|
83
|
+
/** Report a result via onResult callback if provided. */
|
|
84
|
+
const reportResult = async (options, ctx) => {
|
|
85
|
+
if (options?.onResult) {
|
|
86
|
+
await options.onResult(ctx);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/** Execute a trail with validated input. */
|
|
90
|
+
const executeTrail = async (t, validatedInput, ctxOverrides, options) => {
|
|
91
|
+
const ctx = await resolveContext(ctxOverrides, options);
|
|
92
|
+
const layers = options?.layers ?? [];
|
|
93
|
+
const impl = composeLayers(layers, t, t.implementation);
|
|
94
|
+
return impl(validatedInput, ctx);
|
|
95
|
+
};
|
|
96
|
+
/** Create the execute function for a CLI command. */
|
|
97
|
+
const createExecute = (t, fields, _flags, options) => async (parsedArgs, parsedFlags, ctxOverrides) => {
|
|
98
|
+
const mergedInput = mergeArgsAndFlags(parsedArgs, parsedFlags);
|
|
99
|
+
await applyPrompting(fields, mergedInput, options);
|
|
100
|
+
const validated = validateInput(t.input, mergedInput);
|
|
101
|
+
if (validated.isErr()) {
|
|
102
|
+
const errorResult = Result.err(validated.error);
|
|
103
|
+
await reportResult(options, {
|
|
104
|
+
args: parsedArgs,
|
|
105
|
+
flags: parsedFlags,
|
|
106
|
+
input: mergedInput,
|
|
107
|
+
result: errorResult,
|
|
108
|
+
trail: t,
|
|
109
|
+
});
|
|
110
|
+
return errorResult;
|
|
111
|
+
}
|
|
112
|
+
const result = await executeTrail(t, validated.value, ctxOverrides, options);
|
|
113
|
+
await reportResult(options, {
|
|
114
|
+
args: parsedArgs,
|
|
115
|
+
flags: parsedFlags,
|
|
116
|
+
input: validated.value,
|
|
117
|
+
result,
|
|
118
|
+
trail: t,
|
|
119
|
+
});
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
/** Derive and merge flags for a trail. */
|
|
123
|
+
const buildFlags = (fields, destructive, options) => {
|
|
124
|
+
let flags = toFlags(fields);
|
|
125
|
+
if (options?.presets) {
|
|
126
|
+
flags = mergeFlags(options.presets.flat(), flags);
|
|
127
|
+
}
|
|
128
|
+
if (destructive) {
|
|
129
|
+
flags = mergeFlags(dryRunPreset(), flags);
|
|
130
|
+
}
|
|
131
|
+
return flags;
|
|
132
|
+
};
|
|
133
|
+
/** Convert a trail or route into a CLI command when it is publicly exposed. */
|
|
134
|
+
const toCliCommand = (t, options) => {
|
|
135
|
+
const { group, name } = parseTrailId(t.id);
|
|
136
|
+
const fields = deriveFields(t.input, t.fields);
|
|
137
|
+
const flags = buildFlags(fields, t.destructive, options);
|
|
138
|
+
return {
|
|
139
|
+
args: [],
|
|
140
|
+
description: t.description,
|
|
141
|
+
destructive: t.destructive,
|
|
142
|
+
execute: createExecute(t, fields, flags, options),
|
|
143
|
+
flags,
|
|
144
|
+
group,
|
|
145
|
+
idempotent: t.idempotent,
|
|
146
|
+
layers: options?.layers,
|
|
147
|
+
name,
|
|
148
|
+
readOnly: t.readOnly,
|
|
149
|
+
trail: t,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export const buildCliCommands = (app, options) => {
|
|
153
|
+
const commands = [];
|
|
154
|
+
for (const item of app.list()) {
|
|
155
|
+
if (item.kind !== 'trail' && item.kind !== 'hike') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
|
+
const t = item;
|
|
160
|
+
if (t.markers?.['internal'] === true) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
commands.push(toCliCommand(t, options));
|
|
164
|
+
}
|
|
165
|
+
return commands;
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,MAAM,EACN,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAyBnD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,wEAAwE;AACxE,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE,CACtC,GAAG,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAU,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAEnE;;;;GAIG;AACH,MAAM,YAAY,GAAG,CACnB,EAAU,EACmC,EAAE;IAC/C,MAAM,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;QACpB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IACxC,CAAC;IACD,OAAO;QACL,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC5B,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC;KAC7B,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,OAAkB,EAAE,OAAkB,EAAa,EAAE;IACvE,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,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,EAAE,CAAC;YAClD,SAAS;QACX,CAAC;QAED,8DAA8D;QAC9D,MAAM,CAAC,GAAG,IAAgB,CAAC;QAC3B,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE,CAAC;YACrC,SAAS;QACX,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic CLI command model.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces are the intermediate representation that
|
|
5
|
+
* `buildCliCommands()` produces and framework adapters consume.
|
|
6
|
+
* No Commander (or any other framework) imports here.
|
|
7
|
+
*/
|
|
8
|
+
import type { Layer, Result, Trail, TrailContext } from '@ontrails/core';
|
|
9
|
+
/**
|
|
10
|
+
* Type-erased trail reference. At the CLI adapter boundary we lose
|
|
11
|
+
* generic type information since flags/args are parsed as strings.
|
|
12
|
+
* Using `any` here is intentional -- the Zod schema validates at runtime.
|
|
13
|
+
*/
|
|
14
|
+
export type AnyTrail = Trail<any, any>;
|
|
15
|
+
/** A single CLI flag derived from a Zod schema field or preset. */
|
|
16
|
+
export interface CliFlag {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly short?: string | undefined;
|
|
19
|
+
readonly description?: string | undefined;
|
|
20
|
+
readonly type: 'string' | 'number' | 'boolean' | 'string[]' | 'number[]';
|
|
21
|
+
readonly required: boolean;
|
|
22
|
+
readonly default?: unknown | undefined;
|
|
23
|
+
readonly choices?: string[] | undefined;
|
|
24
|
+
readonly variadic: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** A positional CLI argument. */
|
|
27
|
+
export interface CliArg {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly description?: string | undefined;
|
|
30
|
+
readonly required: boolean;
|
|
31
|
+
readonly variadic: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** A framework-agnostic representation of a CLI command. */
|
|
34
|
+
export interface CliCommand {
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly description?: string | undefined;
|
|
37
|
+
readonly group?: string | undefined;
|
|
38
|
+
readonly flags: CliFlag[];
|
|
39
|
+
readonly args: CliArg[];
|
|
40
|
+
readonly trail: AnyTrail;
|
|
41
|
+
readonly layers?: Layer[] | undefined;
|
|
42
|
+
readonly readOnly?: boolean | undefined;
|
|
43
|
+
readonly destructive?: boolean | undefined;
|
|
44
|
+
readonly idempotent?: boolean | undefined;
|
|
45
|
+
execute(parsedArgs: Record<string, unknown>, parsedFlags: Record<string, unknown>, ctx?: Partial<TrailContext>): Promise<Result<unknown, Error>>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMzE;;;;GAIG;AAEH,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAMvC,mEAAmE;AACnE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;IACzE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,C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ED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-agnostic CLI command model.
|
|
3
|
+
*
|
|
4
|
+
* These interfaces are the intermediate representation that
|
|
5
|
+
* `buildCliCommands()` produces and framework adapters consume.
|
|
6
|
+
* No Commander (or any other framework) imports here.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one-liner convenience for wiring an App to Commander.
|
|
3
|
+
*/
|
|
4
|
+
import type { Layer, Topo, TrailContext } from '@ontrails/core';
|
|
5
|
+
import type { ActionResultContext } from '../build.js';
|
|
6
|
+
import type { CliFlag } from '../command.js';
|
|
7
|
+
import type { InputResolver } from '../prompt.js';
|
|
8
|
+
export interface BlazeCliOptions {
|
|
9
|
+
createContext?: (() => TrailContext | Promise<TrailContext>) | undefined;
|
|
10
|
+
description?: string | undefined;
|
|
11
|
+
layers?: Layer[] | undefined;
|
|
12
|
+
name?: string | undefined;
|
|
13
|
+
onResult?: ((ctx: ActionResultContext) => Promise<void>) | undefined;
|
|
14
|
+
presets?: CliFlag[][] | undefined;
|
|
15
|
+
resolveInput?: InputResolver | undefined;
|
|
16
|
+
version?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Wire an App to Commander and parse argv in one call.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { topo } from "@ontrails/core";
|
|
23
|
+
* import { blaze } from "@ontrails/cli/commander";
|
|
24
|
+
* import * as entity from "./trails/entity.ts";
|
|
25
|
+
*
|
|
26
|
+
* const app = topo("myapp", entity);
|
|
27
|
+
* blaze(app);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const blaze: (app: Topo, options?: BlazeCliOptions) => void;
|
|
31
|
+
//# sourceMappingURL=blaze.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blaze.d.ts","sourceRoot":"","sources":["../../src/commander/blaze.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAQlD,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,CAAC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC;IACzE,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IACrE,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,SAAS,CAAC;IAClC,YAAY,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAMD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,IAAI,EAAE,UAAS,eAAoB,KAAG,IAqBhE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one-liner convenience for wiring an App to Commander.
|
|
3
|
+
*/
|
|
4
|
+
import { buildCliCommands } from '../build.js';
|
|
5
|
+
import { defaultOnResult } from '../on-result.js';
|
|
6
|
+
import { toCommander } from './to-commander.js';
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// blaze
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* Wire an App to Commander and parse argv in one call.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { topo } from "@ontrails/core";
|
|
15
|
+
* import { blaze } from "@ontrails/cli/commander";
|
|
16
|
+
* import * as entity from "./trails/entity.ts";
|
|
17
|
+
*
|
|
18
|
+
* const app = topo("myapp", entity);
|
|
19
|
+
* blaze(app);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const blaze = (app, options = {}) => {
|
|
23
|
+
const commands = buildCliCommands(app, {
|
|
24
|
+
createContext: options.createContext,
|
|
25
|
+
layers: options.layers,
|
|
26
|
+
onResult: options.onResult ?? defaultOnResult,
|
|
27
|
+
presets: options.presets,
|
|
28
|
+
resolveInput: options.resolveInput,
|
|
29
|
+
});
|
|
30
|
+
const commanderOpts = {
|
|
31
|
+
name: options.name ?? app.name,
|
|
32
|
+
};
|
|
33
|
+
if (options.version !== undefined) {
|
|
34
|
+
commanderOpts.version = options.version;
|
|
35
|
+
}
|
|
36
|
+
if (options.description !== undefined) {
|
|
37
|
+
commanderOpts.description = options.description;
|
|
38
|
+
}
|
|
39
|
+
const program = toCommander(commands, commanderOpts);
|
|
40
|
+
program.parse();
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=blaze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blaze.js","sourceRoot":"","sources":["../../src/commander/blaze.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC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js","sourceRoot":"","sources":["../../src/commander/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapt framework-agnostic CliCommand[] to a Commander program.
|
|
3
|
+
*/
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import type { CliCommand } from '../command.js';
|
|
6
|
+
export interface ToCommanderOptions {
|
|
7
|
+
description?: string | undefined;
|
|
8
|
+
name?: string | undefined;
|
|
9
|
+
version?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare const toCommander: (commands: CliCommand[], options?: ToCommanderOptions) => Command;
|
|
12
|
+
//# sourceMappingURL=to-commander.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-commander.d.ts","sourceRoot":"","sources":["../../src/commander/to-commander.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAE5C,OAAO,KAAK,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAMzD,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AA0JD,eAAO,MAAM,WAAW,GACtB,UAAU,UAAU,EAAE,EACtB,UAAU,kBAAkB,KAC3B,OAWF,CAAC"}
|