padrone 1.7.1 → 1.8.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 +26 -0
- package/README.md +3 -2
- package/dist/{args-Cnq0nwSM.mjs → args-DrCXxXeP.mjs} +20 -4
- package/dist/args-DrCXxXeP.mjs.map +1 -0
- package/dist/codegen/index.mjs +1 -1
- package/dist/{commands-B_gufyR9.mjs → commands-DLR0rFgq.mjs} +2 -2
- package/dist/{commands-B_gufyR9.mjs.map → commands-DLR0rFgq.mjs.map} +1 -1
- package/dist/{completion-BEuflbDO.mjs → completion-UnBKfGuk.mjs} +2 -2
- package/dist/{completion-BEuflbDO.mjs.map → completion-UnBKfGuk.mjs.map} +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +2 -2
- package/dist/{formatter-DrvhDMrq.d.mts → formatter-CY3KrOEd.d.mts} +3 -2
- package/dist/formatter-CY3KrOEd.d.mts.map +1 -0
- package/dist/{help-BtxLgrF_.mjs → help-B-ZMYyn-.mjs} +16 -6
- package/dist/help-B-ZMYyn-.mjs.map +1 -0
- package/dist/{index-C0Tab27T.d.mts → index-Guyz-CBm.d.mts} +340 -116
- package/dist/index-Guyz-CBm.d.mts.map +1 -0
- package/dist/index.d.mts +17 -160
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +227 -102
- package/dist/index.mjs.map +1 -1
- package/dist/{mcp-6-Jw4Bpq.mjs → mcp-D6PdtjIs.mjs} +4 -4
- package/dist/{mcp-6-Jw4Bpq.mjs.map → mcp-D6PdtjIs.mjs.map} +1 -1
- package/dist/{serve-YVTPzBCl.mjs → serve-PaCLsNoD.mjs} +4 -4
- package/dist/{serve-YVTPzBCl.mjs.map → serve-PaCLsNoD.mjs.map} +1 -1
- package/dist/test.d.mts +1 -1
- package/dist/zod.d.mts +1 -1
- package/package.json +3 -3
- package/src/core/args.ts +24 -1
- package/src/core/create.ts +21 -14
- package/src/core/exec.ts +87 -46
- package/src/core/interceptors.ts +107 -7
- package/src/core/program-methods.ts +12 -2
- package/src/core/validate.ts +26 -7
- package/src/extension/auto-output.ts +1 -1
- package/src/extension/config.ts +2 -1
- package/src/extension/env.ts +5 -4
- package/src/extension/index.ts +1 -0
- package/src/extension/interactive.ts +2 -1
- package/src/extension/logger.ts +1 -1
- package/src/extension/progress-renderer.ts +3 -0
- package/src/extension/progress.ts +37 -3
- package/src/extension/tracing.ts +1 -1
- package/src/index.ts +6 -1
- package/src/output/formatter.ts +6 -1
- package/src/output/help.ts +15 -3
- package/src/types/args-meta.ts +10 -0
- package/src/types/builder.ts +75 -2
- package/src/types/index.ts +3 -0
- package/src/types/interceptor.ts +26 -12
- package/src/util/type-utils.ts +22 -0
- package/dist/args-Cnq0nwSM.mjs.map +0 -1
- package/dist/formatter-DrvhDMrq.d.mts.map +0 -1
- package/dist/help-BtxLgrF_.mjs.map +0 -1
- package/dist/index-C0Tab27T.d.mts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { _ as resolveStdin, c as getCommandRuntime, d as repathCommandTree, f as resolveAllCommands, g as createTerminalReplSession, h as suggestSimilar, i as commandSymbol, l as lazyResolver, n as buildReplCompleter, o as findCommandByName, p as resolveCommand, u as mergeCommands, v as resolveStdinAlways, y as REPL_SIGINT } from "./commands-
|
|
2
|
-
import { a as getJsonSchema, c as parsePositionalConfig, i as extractSchemaMetadata, l as preprocessArgs, n as coerceArgs, o as isArrayField, r as detectUnknownArgs, s as isAsyncStreamField, t as applyValues } from "./args-
|
|
1
|
+
import { _ as resolveStdin, c as getCommandRuntime, d as repathCommandTree, f as resolveAllCommands, g as createTerminalReplSession, h as suggestSimilar, i as commandSymbol, l as lazyResolver, n as buildReplCompleter, o as findCommandByName, p as resolveCommand, u as mergeCommands, v as resolveStdinAlways, y as REPL_SIGINT } from "./commands-DLR0rFgq.mjs";
|
|
2
|
+
import { a as getJsonSchema, c as parsePositionalConfig, i as extractSchemaMetadata, l as preprocessArgs, n as coerceArgs, o as isArrayField, r as detectUnknownArgs, s as isAsyncStreamField, t as applyValues } from "./args-DrCXxXeP.mjs";
|
|
3
3
|
import { i as createStdinStream, r as concatBytes, t as asyncStream } from "./stream-DC4H8YTx.mjs";
|
|
4
|
-
import { a as escapeHtml, i as getVersion, o as resolveOutputFormat, r as getRootCommand, s as colorThemes, t as generateHelp } from "./help-
|
|
4
|
+
import { a as escapeHtml, i as getVersion, o as resolveOutputFormat, r as getRootCommand, s as colorThemes, t as generateHelp } from "./help-B-ZMYyn-.mjs";
|
|
5
5
|
import { a as SignalError, i as RoutingError, n as ConfigError, o as ValidationError, r as PadroneError, s as signalExitCode, t as ActionError } from "./errors-DA4KzK1M.mjs";
|
|
6
6
|
//#region src/core/results.ts
|
|
7
7
|
/**
|
|
@@ -239,7 +239,14 @@ function runInterceptorChain(phase, interceptors, ctx, core) {
|
|
|
239
239
|
for (let i = phaseInterceptors.length - 1; i >= 0; i--) {
|
|
240
240
|
const handler = phaseInterceptors[i][phase];
|
|
241
241
|
const prevNext = next;
|
|
242
|
-
next = (currentCtx) => handler(currentCtx, (overrides) =>
|
|
242
|
+
next = (currentCtx) => handler(currentCtx, (overrides) => {
|
|
243
|
+
if (!overrides) return prevNext(currentCtx);
|
|
244
|
+
if (overrides.context != null && typeof overrides.context === "object") overrides = {
|
|
245
|
+
...overrides,
|
|
246
|
+
context: Object.assign({}, currentCtx.context, overrides.context)
|
|
247
|
+
};
|
|
248
|
+
return prevNext(Object.assign({}, currentCtx, overrides));
|
|
249
|
+
});
|
|
243
250
|
}
|
|
244
251
|
return next(ctx);
|
|
245
252
|
}
|
|
@@ -325,6 +332,70 @@ function wrapWithLifecycle(interceptors, command, input, pipeline, wrapErrorResu
|
|
|
325
332
|
if (result instanceof Promise) return result.then(handleSuccess, runError);
|
|
326
333
|
return handleSuccess(result);
|
|
327
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Wraps a command-level pipeline (validate + execute) with error → shutdown lifecycle hooks.
|
|
337
|
+
* Unlike `wrapWithLifecycle`, this has no `start` phase and uses the resolved command context.
|
|
338
|
+
* Only interceptors exclusive to the command chain (not in root) should be passed here.
|
|
339
|
+
*/
|
|
340
|
+
function wrapWithCommandLifecycle(interceptors, command, input, pipeline, wrapErrorResult, signal, context, runtime, program, caller, pipelineState) {
|
|
341
|
+
const hasError = interceptors.some((p) => p.error);
|
|
342
|
+
const hasShutdown = interceptors.some((p) => p.shutdown);
|
|
343
|
+
if (!hasError && !hasShutdown) return pipeline();
|
|
344
|
+
const runShutdown = (error, result) => {
|
|
345
|
+
if (!hasShutdown) return;
|
|
346
|
+
return runInterceptorChain("shutdown", interceptors, {
|
|
347
|
+
command,
|
|
348
|
+
input,
|
|
349
|
+
error,
|
|
350
|
+
result,
|
|
351
|
+
signal,
|
|
352
|
+
context,
|
|
353
|
+
runtime,
|
|
354
|
+
program,
|
|
355
|
+
caller,
|
|
356
|
+
...pipelineState
|
|
357
|
+
}, () => {});
|
|
358
|
+
};
|
|
359
|
+
const runError = (error) => {
|
|
360
|
+
if (!hasError) {
|
|
361
|
+
const s = runShutdown(error);
|
|
362
|
+
if (s instanceof Promise) return s.then(() => {
|
|
363
|
+
throw error;
|
|
364
|
+
});
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
367
|
+
return thenMaybe(runInterceptorChain("error", interceptors, {
|
|
368
|
+
command,
|
|
369
|
+
input,
|
|
370
|
+
error,
|
|
371
|
+
signal,
|
|
372
|
+
context,
|
|
373
|
+
runtime,
|
|
374
|
+
program,
|
|
375
|
+
caller,
|
|
376
|
+
...pipelineState
|
|
377
|
+
}, () => ({ error })), (er) => {
|
|
378
|
+
if (er.error !== void 0) return thenMaybe(runShutdown(er.error), () => {
|
|
379
|
+
throw er.error;
|
|
380
|
+
});
|
|
381
|
+
const wrapped = wrapErrorResult ? wrapErrorResult(er.result) : er.result;
|
|
382
|
+
return thenMaybe(runShutdown(void 0, wrapped), () => wrapped);
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
const handleSuccess = (result) => {
|
|
386
|
+
const s = runShutdown(void 0, result);
|
|
387
|
+
if (s instanceof Promise) return s.then(() => result);
|
|
388
|
+
return result;
|
|
389
|
+
};
|
|
390
|
+
let result;
|
|
391
|
+
try {
|
|
392
|
+
result = pipeline();
|
|
393
|
+
} catch (e) {
|
|
394
|
+
return runError(e);
|
|
395
|
+
}
|
|
396
|
+
if (result instanceof Promise) return result.then(handleSuccess, runError);
|
|
397
|
+
return handleSuccess(result);
|
|
398
|
+
}
|
|
328
399
|
//#endregion
|
|
329
400
|
//#region src/output/primitives.ts
|
|
330
401
|
function stringifyCell(value) {
|
|
@@ -640,10 +711,7 @@ function createAutoOutputInterceptor(outputConfig) {
|
|
|
640
711
|
if (collected instanceof Promise) return collected.then((v) => ({ result: v }));
|
|
641
712
|
return { result: collected };
|
|
642
713
|
};
|
|
643
|
-
const executedOrPromise = next({ context: {
|
|
644
|
-
...ctx.context,
|
|
645
|
-
output: indicator
|
|
646
|
-
} });
|
|
714
|
+
const executedOrPromise = next({ context: { output: indicator } });
|
|
647
715
|
if (executedOrPromise instanceof Promise) return executedOrPromise.then(handleResult);
|
|
648
716
|
return handleResult(executedOrPromise);
|
|
649
717
|
} }));
|
|
@@ -934,9 +1002,11 @@ function parseCommand(input, rootCommand, findCommandByName) {
|
|
|
934
1002
|
unmatchedTerms
|
|
935
1003
|
};
|
|
936
1004
|
const argsMeta = curCommand.meta?.fields;
|
|
937
|
-
const { flags, aliases } = curCommand.argsSchema ? extractSchemaMetadata(curCommand.argsSchema, argsMeta, curCommand.meta?.autoAlias) : {
|
|
1005
|
+
const { flags, aliases, negatives, customNegation } = curCommand.argsSchema ? extractSchemaMetadata(curCommand.argsSchema, argsMeta, curCommand.meta?.autoAlias) : {
|
|
938
1006
|
flags: {},
|
|
939
|
-
aliases: {}
|
|
1007
|
+
aliases: {},
|
|
1008
|
+
negatives: {},
|
|
1009
|
+
customNegation: /* @__PURE__ */ new Set()
|
|
940
1010
|
};
|
|
941
1011
|
const arrayArguments = /* @__PURE__ */ new Set();
|
|
942
1012
|
if (curCommand.argsSchema) try {
|
|
@@ -951,9 +1021,16 @@ function parseCommand(input, rootCommand, findCommandByName) {
|
|
|
951
1021
|
let key;
|
|
952
1022
|
if (arg.type === "alias" && arg.key.length === 1 && flags[arg.key[0]]) key = [flags[arg.key[0]]];
|
|
953
1023
|
else if (arg.type === "named" && arg.key.length === 1 && aliases[arg.key[0]]) key = [aliases[arg.key[0]]];
|
|
954
|
-
else key
|
|
1024
|
+
else if (arg.type === "named" && arg.key.length === 1 && negatives[arg.key[0]]) {
|
|
1025
|
+
setNestedValue(rawArgs, [negatives[arg.key[0]]], false);
|
|
1026
|
+
continue;
|
|
1027
|
+
} else key = arg.key;
|
|
955
1028
|
const rootKey = key[0];
|
|
956
1029
|
if (arg.type === "named" && arg.negated) {
|
|
1030
|
+
if (customNegation.has(rootKey)) {
|
|
1031
|
+
setNestedValue(rawArgs, [`no-${key.join(".")}`], false);
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
957
1034
|
setNestedValue(rawArgs, key, false);
|
|
958
1035
|
continue;
|
|
959
1036
|
}
|
|
@@ -990,12 +1067,21 @@ function buildCommandArgs(command, rawArgs, positionalArgs) {
|
|
|
990
1067
|
flags: {},
|
|
991
1068
|
aliases: {}
|
|
992
1069
|
});
|
|
1070
|
+
let issues;
|
|
993
1071
|
const positionalConfig = command.meta?.positional ? parsePositionalConfig(command.meta.positional) : [];
|
|
994
1072
|
if (positionalConfig.length > 0) {
|
|
995
1073
|
let argIndex = 0;
|
|
996
1074
|
for (let i = 0; i < positionalConfig.length; i++) {
|
|
997
1075
|
const { name, variadic } = positionalConfig[i];
|
|
998
1076
|
if (argIndex >= positionalArgs.length) break;
|
|
1077
|
+
if (name in preprocessedArgs) {
|
|
1078
|
+
issues ??= [];
|
|
1079
|
+
issues.push({
|
|
1080
|
+
path: [name],
|
|
1081
|
+
message: `Ambiguous argument "${name}": provided both positionally and as a named option`
|
|
1082
|
+
});
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
999
1085
|
if (variadic) {
|
|
1000
1086
|
const nonVariadicAfter = positionalConfig.slice(i + 1).filter((p) => !p.variadic).length;
|
|
1001
1087
|
const variadicEnd = positionalArgs.length - nonVariadicAfter;
|
|
@@ -1011,7 +1097,10 @@ function buildCommandArgs(command, rawArgs, positionalArgs) {
|
|
|
1011
1097
|
}
|
|
1012
1098
|
}
|
|
1013
1099
|
if (command.argsSchema) preprocessedArgs = coerceArgs(preprocessedArgs, command.argsSchema);
|
|
1014
|
-
return
|
|
1100
|
+
return {
|
|
1101
|
+
args: preprocessedArgs,
|
|
1102
|
+
issues
|
|
1103
|
+
};
|
|
1015
1104
|
}
|
|
1016
1105
|
/**
|
|
1017
1106
|
* Detects unknown options in args that aren't defined in the schema.
|
|
@@ -1024,8 +1113,8 @@ function checkUnknownArgs(command, preprocessedArgs) {
|
|
|
1024
1113
|
return unknowns;
|
|
1025
1114
|
}
|
|
1026
1115
|
const argsMeta = command.meta?.fields;
|
|
1027
|
-
const { flags, aliases } = extractSchemaMetadata(command.argsSchema, argsMeta, command.meta?.autoAlias);
|
|
1028
|
-
return detectUnknownArgs(preprocessedArgs, command.argsSchema, flags, aliases);
|
|
1116
|
+
const { flags, aliases, negatives } = extractSchemaMetadata(command.argsSchema, argsMeta, command.meta?.autoAlias);
|
|
1117
|
+
return detectUnknownArgs(preprocessedArgs, command.argsSchema, flags, aliases, negatives);
|
|
1029
1118
|
}
|
|
1030
1119
|
/**
|
|
1031
1120
|
* Validates preprocessed arguments against the command's schema.
|
|
@@ -1071,7 +1160,12 @@ function formatIssueMessages(issues) {
|
|
|
1071
1160
|
* External data sources (stdin, env, config) are not resolved here — use eval() for that.
|
|
1072
1161
|
*/
|
|
1073
1162
|
function coreValidateForParse(command, rawArgs, positionalArgs) {
|
|
1074
|
-
|
|
1163
|
+
const { args: preprocessedArgs, issues } = buildCommandArgs(command, rawArgs, positionalArgs);
|
|
1164
|
+
if (issues) return {
|
|
1165
|
+
args: void 0,
|
|
1166
|
+
argsResult: { issues }
|
|
1167
|
+
};
|
|
1168
|
+
return thenMaybe(validateCommandArgs(command, preprocessedArgs), (v) => v);
|
|
1075
1169
|
}
|
|
1076
1170
|
//#endregion
|
|
1077
1171
|
//#region src/extension/utils.ts
|
|
@@ -1429,7 +1523,11 @@ const interactiveInterceptor = defineInterceptor({
|
|
|
1429
1523
|
const interactivitySuppressed = runtime.interactive === "unsupported" || effectiveInteractive === false || stdinIsPiped && effectiveInteractive !== true;
|
|
1430
1524
|
const forceInteractive = !interactivitySuppressed && effectiveInteractive === true;
|
|
1431
1525
|
if (!(!interactivitySuppressed && runtime.prompt && hasInteractiveConfig(command.meta))) return next();
|
|
1432
|
-
const preprocessedArgs = buildCommandArgs(command, ctx.rawArgs, ctx.positionalArgs);
|
|
1526
|
+
const { args: preprocessedArgs, issues: positionalIssues } = buildCommandArgs(command, ctx.rawArgs, ctx.positionalArgs);
|
|
1527
|
+
if (positionalIssues) return {
|
|
1528
|
+
args: void 0,
|
|
1529
|
+
argsResult: { issues: positionalIssues }
|
|
1530
|
+
};
|
|
1433
1531
|
const unknowns = checkUnknownArgs(command, preprocessedArgs);
|
|
1434
1532
|
if (unknowns.length > 0) return {
|
|
1435
1533
|
args: void 0,
|
|
@@ -1966,6 +2064,7 @@ function execCommand(resolvedInput, ctx, evalOptions, errorMode = "soft", caller
|
|
|
1966
2064
|
const initialContext = evalOptions?.context;
|
|
1967
2065
|
const factoryCache = /* @__PURE__ */ new Map();
|
|
1968
2066
|
const rootInterceptors = resolveRegisteredInterceptors(rootCommand.interceptors ?? [], factoryCache);
|
|
2067
|
+
const rootInterceptorSet = new Set(rootInterceptors);
|
|
1969
2068
|
const runPipeline = (signal, pipelineContext) => {
|
|
1970
2069
|
const parseCtx = {
|
|
1971
2070
|
input: resolvedInput,
|
|
@@ -1983,51 +2082,74 @@ function execCommand(resolvedInput, ctx, evalOptions, errorMode = "soft", caller
|
|
|
1983
2082
|
pipelineState.rawArgs = parsed.rawArgs;
|
|
1984
2083
|
pipelineState.positionalArgs = parsed.positionalArgs;
|
|
1985
2084
|
const commandInterceptors = resolveRegisteredInterceptors(collectInterceptorsFn(command), factoryCache);
|
|
2085
|
+
const commandOnlyInterceptors = commandInterceptors.filter((i) => !rootInterceptorSet.has(i));
|
|
1986
2086
|
const context = resolveContext(command, pipelineContext);
|
|
1987
|
-
const
|
|
2087
|
+
const routedOrPromise = runInterceptorChain("route", commandInterceptors, {
|
|
1988
2088
|
...parseCtx,
|
|
1989
2089
|
command,
|
|
1990
2090
|
rawArgs: parsed.rawArgs,
|
|
1991
2091
|
positionalArgs: parsed.positionalArgs,
|
|
1992
|
-
context
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
const executeCtx = {
|
|
2004
|
-
...validateCtx,
|
|
2005
|
-
args: v.args
|
|
2006
|
-
};
|
|
2007
|
-
const coreExecute = (executeCtx) => {
|
|
2008
|
-
const handler = command.action ?? noop;
|
|
2009
|
-
const actionCtx = {
|
|
2010
|
-
runtime: executeCtx.runtime,
|
|
2011
|
-
command: executeCtx.command,
|
|
2012
|
-
program: ctx.builder,
|
|
2013
|
-
signal: executeCtx.signal,
|
|
2014
|
-
context: executeCtx.context,
|
|
2015
|
-
caller
|
|
2092
|
+
context
|
|
2093
|
+
}, () => {});
|
|
2094
|
+
const continueAfterRoute = () => {
|
|
2095
|
+
const runValidateAndExecute = () => {
|
|
2096
|
+
const validateCtx = {
|
|
2097
|
+
...parseCtx,
|
|
2098
|
+
command,
|
|
2099
|
+
rawArgs: parsed.rawArgs,
|
|
2100
|
+
positionalArgs: parsed.positionalArgs,
|
|
2101
|
+
context,
|
|
2102
|
+
evalInteractive: evalOptions?.interactive
|
|
2016
2103
|
};
|
|
2017
|
-
|
|
2104
|
+
const coreValidate = (validateCtx) => {
|
|
2105
|
+
const { args: preprocessedArgs, issues } = buildCommandArgs(validateCtx.command, validateCtx.rawArgs, validateCtx.positionalArgs);
|
|
2106
|
+
if (issues) return {
|
|
2107
|
+
args: void 0,
|
|
2108
|
+
argsResult: { issues }
|
|
2109
|
+
};
|
|
2110
|
+
return thenMaybe(validateCommandArgs(validateCtx.command, preprocessedArgs), (v) => v);
|
|
2111
|
+
};
|
|
2112
|
+
const validatedOrPromise = runInterceptorChain("validate", commandInterceptors, validateCtx, coreValidate);
|
|
2113
|
+
const continueAfterValidate = (v) => {
|
|
2114
|
+
pipelineState.args = v.args;
|
|
2115
|
+
if (v.argsResult?.issues) return handleValidationIssues(v.argsResult, command, errorMode);
|
|
2116
|
+
const executeCtx = {
|
|
2117
|
+
...validateCtx,
|
|
2118
|
+
args: v.args
|
|
2119
|
+
};
|
|
2120
|
+
const coreExecute = (executeCtx) => {
|
|
2121
|
+
const handler = command.action ?? noop;
|
|
2122
|
+
const actionCtx = {
|
|
2123
|
+
runtime: executeCtx.runtime,
|
|
2124
|
+
command: executeCtx.command,
|
|
2125
|
+
program: ctx.builder,
|
|
2126
|
+
signal: executeCtx.signal,
|
|
2127
|
+
context: executeCtx.context,
|
|
2128
|
+
caller
|
|
2129
|
+
};
|
|
2130
|
+
return { result: handler(executeCtx.args, actionCtx) };
|
|
2131
|
+
};
|
|
2132
|
+
return thenMaybe(runInterceptorChain("execute", commandInterceptors, executeCtx, coreExecute), (e) => {
|
|
2133
|
+
const finalize = (result) => withDrain({
|
|
2134
|
+
command,
|
|
2135
|
+
args: v.args,
|
|
2136
|
+
argsResult: v.argsResult,
|
|
2137
|
+
result
|
|
2138
|
+
});
|
|
2139
|
+
if (e.result instanceof Promise) return e.result.then(finalize);
|
|
2140
|
+
return finalize(e.result);
|
|
2141
|
+
});
|
|
2142
|
+
};
|
|
2143
|
+
return thenMaybe(warnIfUnexpectedAsync(validatedOrPromise, command), continueAfterValidate);
|
|
2018
2144
|
};
|
|
2019
|
-
return
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
});
|
|
2026
|
-
if (e.result instanceof Promise) return e.result.then(finalize);
|
|
2027
|
-
return finalize(e.result);
|
|
2028
|
-
});
|
|
2145
|
+
return wrapWithCommandLifecycle(commandOnlyInterceptors, command, resolvedInput, runValidateAndExecute, (result) => withDrain({
|
|
2146
|
+
command,
|
|
2147
|
+
args: void 0,
|
|
2148
|
+
argsResult: void 0,
|
|
2149
|
+
result
|
|
2150
|
+
}), signal, context, runtime, ctx.builder, caller, pipelineState);
|
|
2029
2151
|
};
|
|
2030
|
-
return thenMaybe(
|
|
2152
|
+
return thenMaybe(routedOrPromise, continueAfterRoute);
|
|
2031
2153
|
};
|
|
2032
2154
|
return thenMaybe(parsedOrPromise, continueAfterParse);
|
|
2033
2155
|
};
|
|
@@ -2260,6 +2382,11 @@ function createProgramMethods(ctx, evalCommand) {
|
|
|
2260
2382
|
if (commandObj.path) parts.push(commandObj.path);
|
|
2261
2383
|
const positionalConfig = commandObj.meta?.positional ? parsePositionalConfig(commandObj.meta.positional) : [];
|
|
2262
2384
|
const positionalNames = new Set(positionalConfig.map((p) => p.name));
|
|
2385
|
+
const negativeKeyword = {};
|
|
2386
|
+
if (commandObj.argsSchema) {
|
|
2387
|
+
const { negatives } = extractSchemaMetadata(commandObj.argsSchema, commandObj.meta?.fields, commandObj.meta?.autoAlias);
|
|
2388
|
+
for (const [keyword, argName] of Object.entries(negatives)) if (!(argName in negativeKeyword)) negativeKeyword[argName] = keyword;
|
|
2389
|
+
}
|
|
2263
2390
|
if (args && typeof args === "object") {
|
|
2264
2391
|
for (const { name, variadic } of positionalConfig) {
|
|
2265
2392
|
const value = args[name];
|
|
@@ -2278,6 +2405,7 @@ function createProgramMethods(ctx, evalCommand) {
|
|
|
2278
2405
|
const stringifyValue = (key, value) => {
|
|
2279
2406
|
if (value === void 0) return;
|
|
2280
2407
|
if (typeof value === "boolean") if (value) parts.push(`--${key}`);
|
|
2408
|
+
else if (negativeKeyword[key]) parts.push(`--${negativeKeyword[key]}`);
|
|
2281
2409
|
else parts.push(`--no-${key}`);
|
|
2282
2410
|
else if (Array.isArray(value)) for (const v of value) {
|
|
2283
2411
|
const vStr = String(v);
|
|
@@ -2457,17 +2585,17 @@ function createProgramMethods(ctx, evalCommand) {
|
|
|
2457
2585
|
};
|
|
2458
2586
|
const completion = async (shell) => {
|
|
2459
2587
|
resolveAllCommands(rootCommand);
|
|
2460
|
-
const { generateCompletionOutput } = await import("./completion-
|
|
2588
|
+
const { generateCompletionOutput } = await import("./completion-UnBKfGuk.mjs");
|
|
2461
2589
|
return generateCompletionOutput(rootCommand, shell);
|
|
2462
2590
|
};
|
|
2463
2591
|
const mcp = async (prefs) => {
|
|
2464
2592
|
resolveAllCommands(rootCommand);
|
|
2465
|
-
const { startMcpServer } = await import("./mcp-
|
|
2593
|
+
const { startMcpServer } = await import("./mcp-D6PdtjIs.mjs");
|
|
2466
2594
|
return startMcpServer(ctx.builder, rootCommand, evalCommand, prefs);
|
|
2467
2595
|
};
|
|
2468
2596
|
const serve = async (prefs) => {
|
|
2469
2597
|
resolveAllCommands(rootCommand);
|
|
2470
|
-
const { startServeServer } = await import("./serve-
|
|
2598
|
+
const { startServeServer } = await import("./serve-PaCLsNoD.mjs");
|
|
2471
2599
|
return startServeServer(ctx.builder, rootCommand, evalCommand, prefs);
|
|
2472
2600
|
};
|
|
2473
2601
|
return {
|
|
@@ -2688,33 +2816,13 @@ function createPadroneBuilder(inputCommand) {
|
|
|
2688
2816
|
execCtx.builder = builder;
|
|
2689
2817
|
return builder;
|
|
2690
2818
|
}
|
|
2691
|
-
/**
|
|
2692
|
-
* Identity helper that contextually types a command builder callback while preserving its full return type.
|
|
2693
|
-
* Use this when defining commands in separate files — the parent program retains exact type information
|
|
2694
|
-
* about the subcommand's args, result, and nested commands.
|
|
2695
|
-
*
|
|
2696
|
-
* @example
|
|
2697
|
-
* ```ts
|
|
2698
|
-
* // my-command.ts
|
|
2699
|
-
* export const myCommand = defineCommand((c) =>
|
|
2700
|
-
* c.arguments(z.object({ name: z.string() }))
|
|
2701
|
-
* .action((args) => console.log(args.name))
|
|
2702
|
-
* );
|
|
2703
|
-
*
|
|
2704
|
-
* // cli.ts
|
|
2705
|
-
* createPadrone('test').command('my-command', myCommand)
|
|
2706
|
-
* ```
|
|
2707
|
-
*
|
|
2708
|
-
* @example With context
|
|
2709
|
-
* ```ts
|
|
2710
|
-
* export const myCommand = defineCommand<{ db: Database }>((c) =>
|
|
2711
|
-
* c.arguments(z.object({ id: z.string() }))
|
|
2712
|
-
* .action((args, ctx) => ctx.context.db.find(args.id))
|
|
2713
|
-
* );
|
|
2714
|
-
* ```
|
|
2715
|
-
*/
|
|
2716
2819
|
function defineCommand(fn) {
|
|
2717
|
-
return fn;
|
|
2820
|
+
if (fn) return fn;
|
|
2821
|
+
const builder = {
|
|
2822
|
+
requires: () => builder,
|
|
2823
|
+
define: (f) => f
|
|
2824
|
+
};
|
|
2825
|
+
return builder;
|
|
2718
2826
|
}
|
|
2719
2827
|
//#endregion
|
|
2720
2828
|
//#region src/extension/completion.ts
|
|
@@ -2736,7 +2844,7 @@ function padroneCompletion() {
|
|
|
2736
2844
|
}), { positional: ["shell"] }).async().action(async (args, ctx) => {
|
|
2737
2845
|
const rootCommand = getRootCommand(ctx.command);
|
|
2738
2846
|
resolveAllCommands(rootCommand);
|
|
2739
|
-
const { detectShell, generateCompletionOutput, setupCompletions } = await import("./completion-
|
|
2847
|
+
const { detectShell, generateCompletionOutput, setupCompletions } = await import("./completion-UnBKfGuk.mjs");
|
|
2740
2848
|
const shell = args.shell;
|
|
2741
2849
|
if (args.setup) {
|
|
2742
2850
|
const resolvedShell = shell ?? await detectShell();
|
|
@@ -3310,11 +3418,7 @@ function loggerInterceptor(rawConfig) {
|
|
|
3310
3418
|
prefix: rawConfig?.prefix ?? "",
|
|
3311
3419
|
timestamps: rawConfig?.timestamps ?? ctxCfg?.timestamps ?? false
|
|
3312
3420
|
};
|
|
3313
|
-
|
|
3314
|
-
return next({ context: {
|
|
3315
|
-
...ctx.context,
|
|
3316
|
-
logger
|
|
3317
|
-
} });
|
|
3421
|
+
return next({ context: { logger: createLogger(ctx.runtime, resolved.level, resolved, ctx.context?.tracing) } });
|
|
3318
3422
|
}
|
|
3319
3423
|
};
|
|
3320
3424
|
});
|
|
@@ -3414,7 +3518,7 @@ function padroneMcp(defaults) {
|
|
|
3414
3518
|
}), { positional: ["transport"] }).async().action(async (args, ctx) => {
|
|
3415
3519
|
const rootCommand = getRootCommand(ctx.command);
|
|
3416
3520
|
resolveAllCommands(rootCommand);
|
|
3417
|
-
const { startMcpServer } = await import("./mcp-
|
|
3521
|
+
const { startMcpServer } = await import("./mcp-D6PdtjIs.mjs");
|
|
3418
3522
|
const transport = args.transport === "stdio" || args.transport === "http" ? args.transport : void 0;
|
|
3419
3523
|
const port = args.port ? parseInt(args.port, 10) : void 0;
|
|
3420
3524
|
const prefs = {
|
|
@@ -3674,6 +3778,7 @@ function createTerminalProgress(message, options) {
|
|
|
3674
3778
|
barFrame++;
|
|
3675
3779
|
render();
|
|
3676
3780
|
}, tickInterval) : void 0;
|
|
3781
|
+
if (timer && typeof timer === "object" && "unref" in timer) timer.unref();
|
|
3677
3782
|
render();
|
|
3678
3783
|
const clear = () => {
|
|
3679
3784
|
if (stopped) return;
|
|
@@ -3858,9 +3963,30 @@ function progressInterceptor(config) {
|
|
|
3858
3963
|
ctx.runtime.output = originalOutput;
|
|
3859
3964
|
ctx.runtime.error = originalError;
|
|
3860
3965
|
};
|
|
3861
|
-
|
|
3966
|
+
const onValidationFailure = (error) => {
|
|
3967
|
+
if (indicator) {
|
|
3968
|
+
cleanup(indicator, msgs.success, msgs.error, error, void 0, true);
|
|
3969
|
+
teardown();
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
const checkResult = (result) => {
|
|
3973
|
+
if (result.argsResult?.issues) onValidationFailure(/* @__PURE__ */ new Error("Validation failed"));
|
|
3974
|
+
return result;
|
|
3975
|
+
};
|
|
3976
|
+
let result;
|
|
3977
|
+
try {
|
|
3978
|
+
result = next();
|
|
3979
|
+
} catch (err) {
|
|
3980
|
+
onValidationFailure(err);
|
|
3981
|
+
throw err;
|
|
3982
|
+
}
|
|
3983
|
+
if (result instanceof Promise) return result.then(checkResult, (err) => {
|
|
3984
|
+
onValidationFailure(err);
|
|
3985
|
+
throw err;
|
|
3986
|
+
});
|
|
3987
|
+
return checkResult(result);
|
|
3862
3988
|
},
|
|
3863
|
-
execute(
|
|
3989
|
+
execute(_ctx, next) {
|
|
3864
3990
|
if (indicator && msgs.validation) indicator.update(msgs.progress);
|
|
3865
3991
|
const effectiveIndicator = indicator ?? noopIndicator;
|
|
3866
3992
|
const onSuccess = (value) => {
|
|
@@ -3876,10 +4002,7 @@ function progressInterceptor(config) {
|
|
|
3876
4002
|
};
|
|
3877
4003
|
let result;
|
|
3878
4004
|
try {
|
|
3879
|
-
result = next({ context: {
|
|
3880
|
-
...ctx.context,
|
|
3881
|
-
progress: effectiveIndicator
|
|
3882
|
-
} });
|
|
4005
|
+
result = next({ context: { progress: effectiveIndicator } });
|
|
3883
4006
|
} catch (err) {
|
|
3884
4007
|
onError(err);
|
|
3885
4008
|
}
|
|
@@ -3897,6 +4020,12 @@ function progressInterceptor(config) {
|
|
|
3897
4020
|
}, (err) => onError(err)) };
|
|
3898
4021
|
onSuccess(result.result);
|
|
3899
4022
|
return result;
|
|
4023
|
+
},
|
|
4024
|
+
shutdown(ctx) {
|
|
4025
|
+
if (indicator) {
|
|
4026
|
+
cleanup(indicator, msgs.success, msgs.error, ctx.error, ctx.result, !!ctx.error);
|
|
4027
|
+
teardown();
|
|
4028
|
+
}
|
|
3900
4029
|
}
|
|
3901
4030
|
};
|
|
3902
4031
|
}).provides();
|
|
@@ -3951,7 +4080,7 @@ function padroneServe(defaults) {
|
|
|
3951
4080
|
})).async().action(async (args, ctx) => {
|
|
3952
4081
|
const rootCommand = getRootCommand(ctx.command);
|
|
3953
4082
|
resolveAllCommands(rootCommand);
|
|
3954
|
-
const { startServeServer } = await import("./serve-
|
|
4083
|
+
const { startServeServer } = await import("./serve-PaCLsNoD.mjs");
|
|
3955
4084
|
const port = args.port ? parseInt(args.port, 10) : void 0;
|
|
3956
4085
|
const prefs = {
|
|
3957
4086
|
...defaults,
|
|
@@ -4046,7 +4175,7 @@ function tracingInterceptor(config) {
|
|
|
4046
4175
|
},
|
|
4047
4176
|
execute(ctx, next) {
|
|
4048
4177
|
rootSpan = tracer.startSpan(`cli ${ctx.command.name}`);
|
|
4049
|
-
|
|
4178
|
+
return next({ context: { tracing: {
|
|
4050
4179
|
tracer,
|
|
4051
4180
|
rootSpan,
|
|
4052
4181
|
span(name, fn) {
|
|
@@ -4071,11 +4200,7 @@ function tracingInterceptor(config) {
|
|
|
4071
4200
|
throw err;
|
|
4072
4201
|
}
|
|
4073
4202
|
}
|
|
4074
|
-
};
|
|
4075
|
-
return next({ context: {
|
|
4076
|
-
...ctx.context,
|
|
4077
|
-
tracing: padroneTracer
|
|
4078
|
-
} });
|
|
4203
|
+
} } });
|
|
4079
4204
|
},
|
|
4080
4205
|
error(ctx, next) {
|
|
4081
4206
|
rootSpan?.recordException(ctx.error);
|