@ontrails/cli 1.0.0-beta.0 → 1.0.0-beta.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.
@@ -1,3 +1,3 @@
1
1
  $ oxlint ./src
2
2
  Found 0 warnings and 0 errors.
3
- Finished in 99ms on 18 files with 93 rules using 24 threads.
3
+ Finished in 31ms on 18 files with 93 rules using 24 threads.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @ontrails/cli
2
2
 
3
+ ## 1.0.0-beta.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix two blocking bugs from real-world migration:
8
+ - Published packages now resolve correctly (workspace:^ instead of workspace:\*)
9
+ - Error forwarding works across different success types (Err no longer carries phantom T)
10
+ - Updated dependencies
11
+ - @ontrails/core@1.0.0-beta.1
12
+
3
13
  ## 1.0.0-beta.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -1,18 +1,8 @@
1
1
  # @ontrails/cli
2
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.
3
+ CLI surface adapter. One `blaze()` call turns a topo into a full CLI with flags, subcommands, help text, and error-mapped exit codes -- all derived from the trail contracts.
4
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
5
+ ## Usage
16
6
 
17
7
  ```typescript
18
8
  import { trail, topo, Result } from '@ontrails/core';
@@ -28,8 +18,6 @@ const app = topo('myapp', { greet });
28
18
  blaze(app);
29
19
  ```
30
20
 
31
- Pure trails can return `Result` directly. The CLI surface still runs the normalized awaitable implementation shape at execution time.
32
-
33
21
  ```bash
34
22
  $ myapp greet --name World
35
23
  Hello, World!
@@ -42,125 +30,59 @@ Options:
42
30
  -h, --help display help for command
43
31
  ```
44
32
 
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.
33
+ For more control, build the commands yourself:
67
34
 
68
35
  ```typescript
69
36
  import { buildCliCommands } from '@ontrails/cli';
37
+ import { toCommander } from '@ontrails/cli/commander';
70
38
 
71
39
  const commands = buildCliCommands(app);
72
- // Each command: name, flags, args, group, trail ref, execute()
40
+ const program = toCommander(commands, { name: 'myapp' });
41
+ program.parse();
73
42
  ```
74
43
 
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 |
44
+ `buildCliCommands` returns a framework-agnostic `CliCommand[]`. Use `toCommander` for Commander, or write your own adapter.
88
45
 
89
- Name conversion: `camelCase` field names become `--kebab-case` flags. `.describe()` on Zod fields becomes help text.
46
+ ## API
90
47
 
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
48
+ | Export | What it does |
49
+ | --- | --- |
50
+ | `blaze(app, options?)` | One-liner: build commands, wire Commander, parse argv |
51
+ | `buildCliCommands(app)` | Framework-agnostic command builder, returns `CliCommand[]` |
52
+ | `toCommander(commands, options?)` | Adapt `CliCommand[]` to a Commander program |
53
+ | `deriveFlags(schema)` | Extract CLI flags from a Zod schema |
54
+ | `output(data, mode)` | Format output as JSON, JSONL, or text |
55
+ | `resolveOutputMode(options)` | Resolve output mode from flags and env vars |
102
56
 
103
- ```typescript
104
- import { output, resolveOutputMode } from '@ontrails/cli';
57
+ See the [API Reference](../../docs/api-reference.md) for the full list.
105
58
 
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
- ```
59
+ ## Flag derivation
110
60
 
111
- Output mode resolution priority: `--json` > `--jsonl` > `--output <mode>` > `TRAILS_JSON=1` > `TRAILS_JSONL=1` > `"text"`.
61
+ Flags come from the Zod schema automatically. No manual flag definitions.
112
62
 
113
- ### Flag Presets
63
+ | Zod type | CLI flag | Notes |
64
+ | --- | --- | --- |
65
+ | `z.string()` | `--name <value>` | Required |
66
+ | `z.boolean()` | `--verbose` | Switch |
67
+ | `z.enum(["a","b"])` | `--format <value>` | With choices |
68
+ | `z.array(z.string())` | `--tag <values...>` | Repeatable |
69
+ | `z.optional(...)` | `--name [value]` | Optional |
114
70
 
115
- - **`outputModePreset()`** -- `--output <mode>`, `--json`, `--jsonl`
116
- - **`cwdPreset()`** -- `--cwd <path>`
117
- - **`dryRunPreset()`** -- `--dry-run` (auto-added for destructive trails)
71
+ `camelCase` fields become `--kebab-case` flags. `.describe()` becomes help text.
118
72
 
119
- ### Built-in Layers
73
+ ## Subcommands
120
74
 
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.
75
+ Dotted trail IDs create subcommand groups: `entity.show` becomes `myapp entity show`.
123
76
 
124
- ### Commander Adapter (Advanced)
77
+ ## Layers
125
78
 
126
- Build the Commander program manually for full control:
79
+ - **`autoIterateLayer`** -- adds `--all` for paginated trails, collects all pages
80
+ - **`dateShortcutsLayer`** -- expands `"today"`, `"7d"`, `"30d"` into ISO date ranges
127
81
 
128
- ```typescript
129
- import { buildCliCommands } from '@ontrails/cli';
130
- import { toCommander } from '@ontrails/cli/commander';
82
+ ## Installation
131
83
 
132
- const commands = buildCliCommands(app);
133
- const program = toCommander(commands, { name: 'myapp' });
134
- program.parse();
84
+ ```bash
85
+ bun add @ontrails/cli commander
135
86
  ```
136
87
 
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)
88
+ `commander` is a peer dependency, required only for the `/commander` subpath.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ontrails/cli",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -15,7 +15,7 @@
15
15
  "clean": "rm -rf dist *.tsbuildinfo"
16
16
  },
17
17
  "dependencies": {
18
- "@ontrails/core": "workspace:*"
18
+ "@ontrails/core": "workspace:^"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "commander": "^14.0.3",