@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,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapt framework-agnostic CliCommand[] to a Commander program.
|
|
3
|
+
*/
|
|
4
|
+
import { exitCodeMap, isTrailsError } from '@ontrails/core';
|
|
5
|
+
import { Command, Option } from 'commander';
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Helpers
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
/** Build the flag string portion of a Commander Option. */
|
|
10
|
+
const buildFlagArgument = (flag) => {
|
|
11
|
+
if (flag.variadic) {
|
|
12
|
+
return flag.required ? '<values...>' : '[values...]';
|
|
13
|
+
}
|
|
14
|
+
return flag.required ? '<value>' : '[value]';
|
|
15
|
+
};
|
|
16
|
+
const buildFlagString = (flag) => {
|
|
17
|
+
const long = `--${flag.name}`;
|
|
18
|
+
const short = flag.short ? `-${flag.short}` : undefined;
|
|
19
|
+
if (flag.type === 'boolean') {
|
|
20
|
+
return short ? `${short}, ${long}` : long;
|
|
21
|
+
}
|
|
22
|
+
const argPart = buildFlagArgument(flag);
|
|
23
|
+
return short ? `${short}, ${long} ${argPart}` : `${long} ${argPart}`;
|
|
24
|
+
};
|
|
25
|
+
/** Build a Commander Option from a CliFlag. */
|
|
26
|
+
const buildOption = (flag) => {
|
|
27
|
+
const opt = new Option(buildFlagString(flag), flag.description);
|
|
28
|
+
if (flag.choices) {
|
|
29
|
+
opt.choices(flag.choices);
|
|
30
|
+
}
|
|
31
|
+
if (flag.default !== undefined) {
|
|
32
|
+
opt.default(flag.default);
|
|
33
|
+
}
|
|
34
|
+
if (flag.type === 'number' || flag.type === 'number[]') {
|
|
35
|
+
opt.argParser(parseFloat);
|
|
36
|
+
}
|
|
37
|
+
return opt;
|
|
38
|
+
};
|
|
39
|
+
/** Add positional args to a Commander subcommand. */
|
|
40
|
+
const buildArgTemplate = (arg) => {
|
|
41
|
+
if (arg.variadic) {
|
|
42
|
+
return arg.required ? `<${arg.name}...>` : `[${arg.name}...]`;
|
|
43
|
+
}
|
|
44
|
+
return arg.required ? `<${arg.name}>` : `[${arg.name}]`;
|
|
45
|
+
};
|
|
46
|
+
const addArgs = (sub, cmd) => {
|
|
47
|
+
for (const arg of cmd.args) {
|
|
48
|
+
const template = buildArgTemplate(arg);
|
|
49
|
+
sub.argument(template, arg.description);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/** Collect positional args from Commander's action callback into a record. */
|
|
53
|
+
const collectPositionalArgs = (cmd, actionArgs) => {
|
|
54
|
+
const parsedArgs = {};
|
|
55
|
+
for (let i = 0; i < cmd.args.length; i += 1) {
|
|
56
|
+
const argDef = cmd.args[i];
|
|
57
|
+
if (argDef) {
|
|
58
|
+
parsedArgs[argDef.name] = actionArgs[i];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return parsedArgs;
|
|
62
|
+
};
|
|
63
|
+
/** Handle execution errors with appropriate exit codes. */
|
|
64
|
+
const handleError = (error) => {
|
|
65
|
+
if (error instanceof Error) {
|
|
66
|
+
process.stderr.write(`Error: ${error.message}\n`);
|
|
67
|
+
if (isTrailsError(error)) {
|
|
68
|
+
process.exit(exitCodeMap[error.category]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
process.stderr.write(`Error: ${String(error)}\n`);
|
|
73
|
+
}
|
|
74
|
+
process.exit(8);
|
|
75
|
+
};
|
|
76
|
+
/** Wire a CliCommand's action to a Commander subcommand. */
|
|
77
|
+
const wireAction = (sub, cmd) => {
|
|
78
|
+
sub.action(async (...actionArgs) => {
|
|
79
|
+
const opts = sub.opts();
|
|
80
|
+
const parsedArgs = collectPositionalArgs(cmd, actionArgs);
|
|
81
|
+
try {
|
|
82
|
+
await cmd.execute(parsedArgs, opts);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
handleError(error);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
/** Attach a subcommand to its group or to the top-level program. */
|
|
90
|
+
const attachToGroup = (sub, cmd, program, groups) => {
|
|
91
|
+
if (cmd.group) {
|
|
92
|
+
let groupCmd = groups.get(cmd.group);
|
|
93
|
+
if (!groupCmd) {
|
|
94
|
+
groupCmd = new Command(cmd.group);
|
|
95
|
+
groups.set(cmd.group, groupCmd);
|
|
96
|
+
program.addCommand(groupCmd);
|
|
97
|
+
}
|
|
98
|
+
groupCmd.addCommand(sub);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
program.addCommand(sub);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/** Apply options to a Commander program. */
|
|
105
|
+
const applyOptions = (program, options) => {
|
|
106
|
+
if (options?.name) {
|
|
107
|
+
program.name(options.name);
|
|
108
|
+
}
|
|
109
|
+
if (options?.version) {
|
|
110
|
+
program.version(options.version);
|
|
111
|
+
}
|
|
112
|
+
if (options?.description) {
|
|
113
|
+
program.description(options.description);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// toCommander
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* Convert CliCommand[] into a configured Commander program.
|
|
121
|
+
*
|
|
122
|
+
* Groups commands by their `group` field into parent/subcommand structure.
|
|
123
|
+
* Wires each command's `.action()` to call `execute()` and handle errors.
|
|
124
|
+
*/
|
|
125
|
+
/** Build a Commander subcommand from a CliCommand. */
|
|
126
|
+
const buildSubcommand = (cmd) => {
|
|
127
|
+
const sub = new Command(cmd.name);
|
|
128
|
+
if (cmd.description) {
|
|
129
|
+
sub.description(cmd.description);
|
|
130
|
+
}
|
|
131
|
+
for (const flag of cmd.flags) {
|
|
132
|
+
sub.addOption(buildOption(flag));
|
|
133
|
+
}
|
|
134
|
+
addArgs(sub, cmd);
|
|
135
|
+
wireAction(sub, cmd);
|
|
136
|
+
return sub;
|
|
137
|
+
};
|
|
138
|
+
export const toCommander = (commands, options) => {
|
|
139
|
+
const program = new Command();
|
|
140
|
+
applyOptions(program, options);
|
|
141
|
+
const groups = new Map();
|
|
142
|
+
for (const cmd of commands) {
|
|
143
|
+
const sub = buildSubcommand(cmd);
|
|
144
|
+
attachToGroup(sub, cmd, program, groups);
|
|
145
|
+
}
|
|
146
|
+
return program;
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=to-commander.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-commander.js","sourceRoot":"","sources":["../../src/commander/to-commander.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAc5C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,2DAA2D;AAC3D,MAAM,iBAAiB,GAAG,CAAC,IAAa,EAAU,EAAE;IAClD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;IACvD,CAAC;IACD,OAAO,IAAI,CAA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AAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,QAAsB,EACtB,OAA4B,EACnB,EAAE;IACX,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE1C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QACjC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
package/dist/flags.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flag derivation from surface-agnostic fields and reusable flag presets.
|
|
3
|
+
*/
|
|
4
|
+
import type { Field } from '@ontrails/core';
|
|
5
|
+
import type { z } from 'zod';
|
|
6
|
+
import type { CliFlag } from './command.js';
|
|
7
|
+
/** Convert derived fields to CLI flags. */
|
|
8
|
+
export declare const toFlags: (fields: readonly Field[]) => CliFlag[];
|
|
9
|
+
/** Derive CLI flags from a Zod input schema. */
|
|
10
|
+
export declare const deriveFlags: (schema: z.ZodType) => CliFlag[];
|
|
11
|
+
/** Flags for output mode selection: --output, --json, --jsonl */
|
|
12
|
+
export declare const outputModePreset: () => CliFlag[];
|
|
13
|
+
/** Flag for working directory override: --cwd */
|
|
14
|
+
export declare const cwdPreset: () => CliFlag[];
|
|
15
|
+
/** Flag for dry-run mode: --dry-run */
|
|
16
|
+
export declare const dryRunPreset: () => CliFlag[];
|
|
17
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAiD5C,2CAA2C;AAC3C,eAAO,MAAM,OAAO,GAAI,QAAQ,SAAS,KAAK,EAAE,KAAG,OAAO,EACnC,CAAC;AA2HxB,gDAAgD;AAChD,eAAO,MAAM,WAAW,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,OAAO,EAYtD,CAAC;AAMF,iEAAiE;AACjE,eAAO,MAAM,gBAAgB,QAAO,OAAO,EAyB1C,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,SAAS,QAAO,OAAO,EAQnC,CAAC;AAEF,uCAAuC;AACvC,eAAO,MAAM,YAAY,QAAO,OAAO,EAStC,CAAC"}
|
package/dist/flags.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flag derivation from surface-agnostic fields and reusable flag presets.
|
|
3
|
+
*/
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Helpers
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
/** Convert camelCase to kebab-case. */
|
|
8
|
+
const toKebab = (str) => str.replaceAll(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);
|
|
9
|
+
const fieldTypeToCliFlag = {
|
|
10
|
+
boolean: { type: 'boolean', variadic: false },
|
|
11
|
+
enum: { type: 'string', variadic: false },
|
|
12
|
+
multiselect: { type: 'string[]', variadic: true },
|
|
13
|
+
number: { type: 'number', variadic: false },
|
|
14
|
+
string: { type: 'string', variadic: false },
|
|
15
|
+
};
|
|
16
|
+
/** Convert a derived field into a CLI flag descriptor. */
|
|
17
|
+
const toCliFlag = (field) => {
|
|
18
|
+
const shape = fieldTypeToCliFlag[field.type];
|
|
19
|
+
return {
|
|
20
|
+
choices: field.options?.map((option) => option.value),
|
|
21
|
+
default: field.default,
|
|
22
|
+
description: field.label,
|
|
23
|
+
name: toKebab(field.name),
|
|
24
|
+
required: field.required,
|
|
25
|
+
type: shape.type,
|
|
26
|
+
variadic: shape.variadic,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Public API
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/** Convert derived fields to CLI flags. */
|
|
33
|
+
export const toFlags = (fields) => fields.map(toCliFlag);
|
|
34
|
+
/** Get the inner type from an optional or default wrapper. */
|
|
35
|
+
const getInnerType = (current) => current._zod.def['innerType'];
|
|
36
|
+
/** Propagate description from an inner type. */
|
|
37
|
+
const propagateDescription = (inner, state) => {
|
|
38
|
+
if (inner.description) {
|
|
39
|
+
state.description = inner.description;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/** Step one unwrap level for optional/default fields. */
|
|
43
|
+
const unwrapStep = (current, state) => {
|
|
44
|
+
const defType = current._zod.def['type'];
|
|
45
|
+
if (defType !== 'optional' && defType !== 'default') {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
state.required = false;
|
|
49
|
+
if (defType === 'default') {
|
|
50
|
+
state.defaultValue = current._zod.def['defaultValue'];
|
|
51
|
+
}
|
|
52
|
+
const inner = getInnerType(current);
|
|
53
|
+
propagateDescription(inner, state);
|
|
54
|
+
return inner;
|
|
55
|
+
};
|
|
56
|
+
/** Unwrap optional/default wrappers, collecting metadata. */
|
|
57
|
+
const unwrap = (schema) => {
|
|
58
|
+
const state = {
|
|
59
|
+
defaultValue: undefined,
|
|
60
|
+
description: schema.description,
|
|
61
|
+
required: true,
|
|
62
|
+
};
|
|
63
|
+
let current = schema;
|
|
64
|
+
// eslint-disable-next-line no-constant-condition
|
|
65
|
+
while (true) {
|
|
66
|
+
const next = unwrapStep(current, state);
|
|
67
|
+
if (next === null) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
current = next;
|
|
71
|
+
}
|
|
72
|
+
return { ...state, inner: current };
|
|
73
|
+
};
|
|
74
|
+
const flagShapeByDef = {
|
|
75
|
+
array: (schema) => {
|
|
76
|
+
const element = schema._zod.def['element'];
|
|
77
|
+
const elementType = element._zod.def['type'];
|
|
78
|
+
if (elementType === 'number') {
|
|
79
|
+
return { type: 'number[]', variadic: true };
|
|
80
|
+
}
|
|
81
|
+
return { type: 'string[]', variadic: true };
|
|
82
|
+
},
|
|
83
|
+
boolean: () => ({ type: 'boolean', variadic: false }),
|
|
84
|
+
enum: (schema) => {
|
|
85
|
+
const entries = schema._zod.def['entries'];
|
|
86
|
+
return {
|
|
87
|
+
choices: Object.values(entries),
|
|
88
|
+
type: 'string',
|
|
89
|
+
variadic: false,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
number: () => ({ type: 'number', variadic: false }),
|
|
93
|
+
string: () => ({ type: 'string', variadic: false }),
|
|
94
|
+
};
|
|
95
|
+
/** Derive the CLI flag shape for an unwrapped Zod field. */
|
|
96
|
+
const deriveFlagShape = (schema) => {
|
|
97
|
+
const defType = schema._zod.def['type'];
|
|
98
|
+
const deriveShape = flagShapeByDef[defType];
|
|
99
|
+
return deriveShape
|
|
100
|
+
? deriveShape(schema)
|
|
101
|
+
: { type: 'string', variadic: false };
|
|
102
|
+
};
|
|
103
|
+
/** Derive a single CLI flag from an object shape entry. */
|
|
104
|
+
const deriveFlag = (key, value) => {
|
|
105
|
+
const { inner, required, defaultValue, description } = unwrap(value);
|
|
106
|
+
const { choices, type, variadic } = deriveFlagShape(inner);
|
|
107
|
+
return {
|
|
108
|
+
choices,
|
|
109
|
+
default: defaultValue,
|
|
110
|
+
description: description ?? inner.description,
|
|
111
|
+
name: toKebab(key),
|
|
112
|
+
required,
|
|
113
|
+
type,
|
|
114
|
+
variadic,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/** Derive CLI flags from a Zod input schema. */
|
|
118
|
+
export const deriveFlags = (schema) => {
|
|
119
|
+
const zod = schema;
|
|
120
|
+
if (zod._zod.def['type'] !== 'object') {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
const shape = zod._zod.def['shape'];
|
|
124
|
+
if (!shape) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return Object.entries(shape).map(([key, value]) => deriveFlag(key, value));
|
|
128
|
+
};
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// Presets
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
/** Flags for output mode selection: --output, --json, --jsonl */
|
|
133
|
+
export const outputModePreset = () => [
|
|
134
|
+
{
|
|
135
|
+
choices: ['text', 'json', 'jsonl'],
|
|
136
|
+
default: 'text',
|
|
137
|
+
description: 'Output format',
|
|
138
|
+
name: 'output',
|
|
139
|
+
required: false,
|
|
140
|
+
short: 'o',
|
|
141
|
+
type: 'string',
|
|
142
|
+
variadic: false,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
description: 'Shorthand for --output json',
|
|
146
|
+
name: 'json',
|
|
147
|
+
required: false,
|
|
148
|
+
type: 'boolean',
|
|
149
|
+
variadic: false,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
description: 'Shorthand for --output jsonl',
|
|
153
|
+
name: 'jsonl',
|
|
154
|
+
required: false,
|
|
155
|
+
type: 'boolean',
|
|
156
|
+
variadic: false,
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
/** Flag for working directory override: --cwd */
|
|
160
|
+
export const cwdPreset = () => [
|
|
161
|
+
{
|
|
162
|
+
description: 'Working directory override',
|
|
163
|
+
name: 'cwd',
|
|
164
|
+
required: false,
|
|
165
|
+
type: 'string',
|
|
166
|
+
variadic: false,
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
/** Flag for dry-run mode: --dry-run */
|
|
170
|
+
export const dryRunPreset = () => [
|
|
171
|
+
{
|
|
172
|
+
default: false,
|
|
173
|
+
description: 'Execute without side effects',
|
|
174
|
+
name: 'dry-run',
|
|
175
|
+
required: false,
|
|
176
|
+
type: 'boolean',
|
|
177
|
+
variadic: false,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,uCAAuC;AACvC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE,CACtC,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AAe3D,MAAM,kBAAkB,GAAwC;IAC9D,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC7C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzC,WAAW,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;IACjD,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC3C,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE;CAC5C,CAAC;AAEF,0DAA0D;AAC1D,MAAM,SAAS,GAAG,CAAC,KAAY,EAAW,EAAE;IAC1C,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO,E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AQ,EAAE,KAAK;QACf,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,iDAAiD;AACjD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAc,EAAE,CAAC;IACxC;QACE,WAAW,EAAE,4BAA4B;QACzC,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,uCAAuC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAc,EAAE,CAAC;IAC3C;QACE,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,8BAA8B;QAC3C,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { AnyTrail, CliCommand, CliFlag, CliArg } from './command.js';
|
|
2
|
+
export { buildCliCommands } from './build.js';
|
|
3
|
+
export type { BuildCliCommandsOptions, ActionResultContext } from './build.js';
|
|
4
|
+
export { deriveFlags, outputModePreset, cwdPreset, dryRunPreset, } from './flags.js';
|
|
5
|
+
export { output, resolveOutputMode } from './output.js';
|
|
6
|
+
export type { OutputMode } from './output.js';
|
|
7
|
+
export { defaultOnResult } from './on-result.js';
|
|
8
|
+
export { passthroughResolver, isInteractive } from './prompt.js';
|
|
9
|
+
export type { Field, InputResolver, ResolveInputOptions } from './prompt.js';
|
|
10
|
+
export { autoIterateLayer, dateShortcutsLayer } from './layers.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAG/E,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG7E,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Build
|
|
2
|
+
export { buildCliCommands } from './build.js';
|
|
3
|
+
// Flags
|
|
4
|
+
export { deriveFlags, outputModePreset, cwdPreset, dryRunPreset, } from './flags.js';
|
|
5
|
+
// Output
|
|
6
|
+
export { output, resolveOutputMode } from './output.js';
|
|
7
|
+
// onResult
|
|
8
|
+
export { defaultOnResult } from './on-result.js';
|
|
9
|
+
// Prompt
|
|
10
|
+
export { passthroughResolver, isInteractive } from './prompt.js';
|
|
11
|
+
// Layers
|
|
12
|
+
export { autoIterateLayer, dateShortcutsLayer } from './layers.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,QAAQ;AACR,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,QAAQ;AACR,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGxD,WAAW;AACX,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,SAAS;AACT,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjE,SAAS;AACT,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/layers.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific layers shipped with @ontrails/cli.
|
|
3
|
+
*/
|
|
4
|
+
import type { Layer } from '@ontrails/core';
|
|
5
|
+
/**
|
|
6
|
+
* Automatically iterates paginated results when --all flag is present.
|
|
7
|
+
*
|
|
8
|
+
* When a trail's output matches the pagination pattern (items, hasMore,
|
|
9
|
+
* nextCursor) and the input contains `all: true`, this layer repeatedly
|
|
10
|
+
* calls the implementation with incrementing cursors and collects all items.
|
|
11
|
+
*/
|
|
12
|
+
export declare const autoIterateLayer: Layer;
|
|
13
|
+
/**
|
|
14
|
+
* Expands date shortcut strings into ISO date ranges.
|
|
15
|
+
*
|
|
16
|
+
* When a trail's input has `since` or `until` fields, this layer
|
|
17
|
+
* checks for shortcuts like "today", "yesterday", "7d", "30d",
|
|
18
|
+
* "this-week", "this-month" and expands them to ISO 8601 dates.
|
|
19
|
+
*/
|
|
20
|
+
export declare const dateShortcutsLayer: Layer;
|
|
21
|
+
//# sourceMappingURL=layers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layers.d.ts","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAkB,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAiHnE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAsB9B,CAAC;AA4DF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAiBhC,CAAC"}
|
package/dist/layers.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-specific layers shipped with @ontrails/cli.
|
|
3
|
+
*/
|
|
4
|
+
import { Result } from '@ontrails/core';
|
|
5
|
+
/** Check if a trail's output schema looks like a paginated response. */
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
const isPaginatedOutput = (trail) => {
|
|
8
|
+
if (!trail.output) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const s = trail.output;
|
|
12
|
+
const defType = s._zod.def['type'];
|
|
13
|
+
if (defType !== 'object') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const shape = s._zod.def['shape'];
|
|
17
|
+
if (!shape) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return 'items' in shape && 'hasMore' in shape && 'nextCursor' in shape;
|
|
21
|
+
};
|
|
22
|
+
/** Check if a trail's input schema has since/until fields. */
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
const hasDateRangeFields = (trail) => {
|
|
25
|
+
const s = trail.input;
|
|
26
|
+
const defType = s._zod.def['type'];
|
|
27
|
+
if (defType !== 'object') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const shape = s._zod.def['shape'];
|
|
31
|
+
if (!shape) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return 'since' in shape || 'until' in shape;
|
|
35
|
+
};
|
|
36
|
+
/** Fetch one page and extract items. Returns error result or page data. */
|
|
37
|
+
const fetchPage = async (inp, cursor, implementation, ctx) => {
|
|
38
|
+
const pageInput = { ...inp, cursor };
|
|
39
|
+
const result = await implementation(pageInput, ctx);
|
|
40
|
+
if (result.isErr()) {
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
return Result.ok(result.value);
|
|
44
|
+
};
|
|
45
|
+
/** Accumulate items from a page and return the next cursor if there are more. */
|
|
46
|
+
const accumulatePage = (page, allItems) => {
|
|
47
|
+
allItems.push(...page.items);
|
|
48
|
+
return page.hasMore && page.nextCursor ? page.nextCursor : undefined;
|
|
49
|
+
};
|
|
50
|
+
/** Collect all pages into a single result. */
|
|
51
|
+
const collectAllPages = async (inp, implementation, ctx) => {
|
|
52
|
+
const allItems = [];
|
|
53
|
+
let cursor;
|
|
54
|
+
for (;;) {
|
|
55
|
+
const pageResult = await fetchPage(inp, cursor, implementation, ctx);
|
|
56
|
+
if (pageResult.isErr()) {
|
|
57
|
+
return pageResult;
|
|
58
|
+
}
|
|
59
|
+
cursor = accumulatePage(pageResult.value, allItems);
|
|
60
|
+
if (cursor === undefined) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Result.ok({ hasMore: false, items: allItems });
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Automatically iterates paginated results when --all flag is present.
|
|
68
|
+
*
|
|
69
|
+
* When a trail's output matches the pagination pattern (items, hasMore,
|
|
70
|
+
* nextCursor) and the input contains `all: true`, this layer repeatedly
|
|
71
|
+
* calls the implementation with incrementing cursors and collects all items.
|
|
72
|
+
*/
|
|
73
|
+
export const autoIterateLayer = {
|
|
74
|
+
description: 'Auto-paginate results when --all flag is set',
|
|
75
|
+
name: 'autoIterate',
|
|
76
|
+
wrap(trail, implementation) {
|
|
77
|
+
if (!isPaginatedOutput(trail)) {
|
|
78
|
+
return implementation;
|
|
79
|
+
}
|
|
80
|
+
return (input, ctx) => {
|
|
81
|
+
const inp = input;
|
|
82
|
+
if (!inp.all) {
|
|
83
|
+
return implementation(input, ctx);
|
|
84
|
+
}
|
|
85
|
+
return collectAllPages(inp, implementation, ctx);
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// dateShortcutsLayer
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
/** Build a date relative to today with a day offset. */
|
|
93
|
+
const daysAgo = (days) => {
|
|
94
|
+
const now = new Date();
|
|
95
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - days).toISOString();
|
|
96
|
+
};
|
|
97
|
+
const dateShortcuts = {
|
|
98
|
+
'this-month': () => {
|
|
99
|
+
const now = new Date();
|
|
100
|
+
return new Date(now.getFullYear(), now.getMonth(), 1).toISOString();
|
|
101
|
+
},
|
|
102
|
+
'this-week': () => {
|
|
103
|
+
const now = new Date();
|
|
104
|
+
const dayOfWeek = now.getDay();
|
|
105
|
+
const diff = dayOfWeek === 0 ? 6 : dayOfWeek - 1;
|
|
106
|
+
return daysAgo(diff);
|
|
107
|
+
},
|
|
108
|
+
today: () => daysAgo(0),
|
|
109
|
+
yesterday: () => daysAgo(1),
|
|
110
|
+
};
|
|
111
|
+
/** Expand a date shortcut to an ISO date string. */
|
|
112
|
+
const expandDateShortcut = (shortcut) => {
|
|
113
|
+
const handler = dateShortcuts[shortcut];
|
|
114
|
+
if (handler) {
|
|
115
|
+
return handler();
|
|
116
|
+
}
|
|
117
|
+
const match = /^(\d+)d$/.exec(shortcut);
|
|
118
|
+
if (match?.[1]) {
|
|
119
|
+
return daysAgo(Number(match[1]));
|
|
120
|
+
}
|
|
121
|
+
return undefined;
|
|
122
|
+
};
|
|
123
|
+
/** Expand since/until shortcuts in an input record. */
|
|
124
|
+
const expandDateFields = (inp) => {
|
|
125
|
+
const modified = { ...inp };
|
|
126
|
+
for (const field of ['since', 'until']) {
|
|
127
|
+
if (typeof inp[field] === 'string') {
|
|
128
|
+
const expanded = expandDateShortcut(inp[field]);
|
|
129
|
+
if (expanded) {
|
|
130
|
+
modified[field] = expanded;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return modified;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Expands date shortcut strings into ISO date ranges.
|
|
138
|
+
*
|
|
139
|
+
* When a trail's input has `since` or `until` fields, this layer
|
|
140
|
+
* checks for shortcuts like "today", "yesterday", "7d", "30d",
|
|
141
|
+
* "this-week", "this-month" and expands them to ISO 8601 dates.
|
|
142
|
+
*/
|
|
143
|
+
export const dateShortcutsLayer = {
|
|
144
|
+
description: 'Expand date shortcuts (today, 7d, etc.) to ISO dates',
|
|
145
|
+
name: 'dateShortcuts',
|
|
146
|
+
wrap(trail, implementation) {
|
|
147
|
+
if (!hasDateRangeFields(trail)) {
|
|
148
|
+
return implementation;
|
|
149
|
+
}
|
|
150
|
+
return (input, ctx) => {
|
|
151
|
+
const modified = expandDateFields(input);
|
|
152
|
+
return implementation(modified, ctx);
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=layers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layers.js","sourceRoot":"","sources":["../src/layers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAYxC,wEAAwE;AACxE,8DAA8D;AAC9D,MAAM,iBAAiB,GAAG,CAAC,KAAsB,EAAW,EAAE;IAC5D,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,CAAC,GAAG,KAAK,CAAC,MAAiC,CAAC;IAClD,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC;IAC7C,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAA6C,CAAC;IAC9E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,OAAO,IA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CLI commands.
|
|
3
|
+
*/
|
|
4
|
+
import type { ActionResultContext } from './build.js';
|
|
5
|
+
/**
|
|
6
|
+
* The batteries-included result handler.
|
|
7
|
+
*
|
|
8
|
+
* - On error: throws the error (lets the program's error handler produce exit code)
|
|
9
|
+
* - On success: resolves output mode from flags, pipes value through `output()`
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultOnResult: (ctx: ActionResultContext) => Promise<void>;
|
|
12
|
+
//# sourceMappingURL=on-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-result.d.ts","sourceRoot":"","sources":["../src/on-result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAOtD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,mBAAmB,KACvB,OAAO,CAAC,IAAI,CAOd,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default result handler for CLI commands.
|
|
3
|
+
*/
|
|
4
|
+
import { output, resolveOutputMode } from './output.js';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// defaultOnResult
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
/**
|
|
9
|
+
* The batteries-included result handler.
|
|
10
|
+
*
|
|
11
|
+
* - On error: throws the error (lets the program's error handler produce exit code)
|
|
12
|
+
* - On success: resolves output mode from flags, pipes value through `output()`
|
|
13
|
+
*/
|
|
14
|
+
export const defaultOnResult = async (ctx) => {
|
|
15
|
+
if (ctx.result.isErr()) {
|
|
16
|
+
throw ctx.result.error;
|
|
17
|
+
}
|
|
18
|
+
const { mode } = resolveOutputMode(ctx.flags);
|
|
19
|
+
await output(ctx.result.value, mode);
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=on-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-result.js","sourceRoot":"","sources":["../src/on-result.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExD,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAAwB,EACT,EAAE;IACjB,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;QACvB,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC,CAAC"}
|