hacksh 0.15.0 → 0.16.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/README.md +371 -285
- package/dist/{command-pPKGCjNA.d.ts → command-B-Ok_6KW.d.ts} +103 -76
- package/dist/index.d.ts +3 -3
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/dist/{pretty-BFub611x.js → pretty-DJ2CE6TU.js} +25 -9
- package/dist/pretty-DJ2CE6TU.js.map +1 -0
- package/dist/printer-api.d.ts +4 -3
- package/dist/printer-api.js +1 -1
- package/package.json +1 -1
- package/dist/pretty-BFub611x.js.map +0 -1
|
@@ -1,4 +1,78 @@
|
|
|
1
1
|
import { $ZodIssue, $ZodObject, JSONSchemaMeta, output } from "zod/v4/core";
|
|
2
|
+
//#region src/exec.d.ts
|
|
3
|
+
type Environment = Readonly<Record<string, string | undefined>>;
|
|
4
|
+
interface ExecOptions {
|
|
5
|
+
cwd?: string;
|
|
6
|
+
env?: Environment;
|
|
7
|
+
input?: string;
|
|
8
|
+
reject?: boolean;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
maxBuffer?: number;
|
|
12
|
+
forceKillAfterDelay?: number;
|
|
13
|
+
stdin?: "pipe" | "inherit";
|
|
14
|
+
stdout?: "pipe" | "inherit";
|
|
15
|
+
stderr?: "pipe" | "inherit";
|
|
16
|
+
interactive?: boolean;
|
|
17
|
+
display?: boolean;
|
|
18
|
+
redact?: readonly string[];
|
|
19
|
+
dryRun?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface ExecCommand {
|
|
22
|
+
file: string;
|
|
23
|
+
args: readonly string[];
|
|
24
|
+
cwd: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
interface ExecSuccess {
|
|
27
|
+
status: "succeeded";
|
|
28
|
+
command: ExecCommand;
|
|
29
|
+
stdout: string;
|
|
30
|
+
stderr: string;
|
|
31
|
+
exitCode: 0;
|
|
32
|
+
}
|
|
33
|
+
type ExecFailure = {
|
|
34
|
+
status: "failed";
|
|
35
|
+
command: ExecCommand;
|
|
36
|
+
stdout: string;
|
|
37
|
+
stderr: string;
|
|
38
|
+
} & ({
|
|
39
|
+
reason: "exit-code";
|
|
40
|
+
exitCode: number;
|
|
41
|
+
} | {
|
|
42
|
+
reason: "signal";
|
|
43
|
+
signal: string;
|
|
44
|
+
} | {
|
|
45
|
+
reason: "spawn";
|
|
46
|
+
error: Error;
|
|
47
|
+
} | {
|
|
48
|
+
reason: "timeout" | "aborted" | "output-limit";
|
|
49
|
+
} | {
|
|
50
|
+
reason: "json-output" | "non-interactive" | "overlapping";
|
|
51
|
+
});
|
|
52
|
+
type ExecFailureReason = ExecFailure["reason"];
|
|
53
|
+
type ExecResult = ExecSuccess | ExecFailure;
|
|
54
|
+
interface ExecSkipped {
|
|
55
|
+
status: "skipped";
|
|
56
|
+
command: ExecCommand;
|
|
57
|
+
}
|
|
58
|
+
type ExecOutcome<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? ExecResult : ExecSuccess : ExecSuccess;
|
|
59
|
+
type SpecifiedDryRun<O> = "dryRun" extends keyof O ? O["dryRun"] : false;
|
|
60
|
+
type ReturnsFailure<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? true : false : false;
|
|
61
|
+
type AbortedFailure = {
|
|
62
|
+
status: "failed";
|
|
63
|
+
command: ExecCommand;
|
|
64
|
+
stdout: string;
|
|
65
|
+
stderr: string;
|
|
66
|
+
reason: "aborted";
|
|
67
|
+
};
|
|
68
|
+
type DefiniteSkip<O extends ExecOptions> = ReturnsFailure<O> extends true ? ExecSkipped | AbortedFailure : ExecSkipped;
|
|
69
|
+
type ExecReturn<O extends ExecOptions> = true extends SpecifiedDryRun<O> ? false extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : undefined extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : DefiniteSkip<O> : ExecOutcome<O>;
|
|
70
|
+
type RejectInheritedInput<O> = O extends {
|
|
71
|
+
input: string;
|
|
72
|
+
stdin: "inherit";
|
|
73
|
+
} ? never : unknown;
|
|
74
|
+
type Exec = <const O extends ExecOptions = {}>(file: string, args?: readonly string[], options?: O & { [K in Exclude<keyof O, keyof ExecOptions>]: never; } & RejectInheritedInput<O>) => Promise<ExecReturn<O>>;
|
|
75
|
+
//#endregion
|
|
2
76
|
//#region src/errors.d.ts
|
|
3
77
|
interface HackshIssue {
|
|
4
78
|
arg: string;
|
|
@@ -136,16 +210,21 @@ declare function showUsage(command: AnyCommandDef, options: ShowUsageOptions): P
|
|
|
136
210
|
type PrintStream = "stdout" | "stderr";
|
|
137
211
|
type OutputPreference = "auto" | "pretty" | "json";
|
|
138
212
|
type OutputFormat = Exclude<OutputPreference, "auto">;
|
|
213
|
+
interface StreamColors {
|
|
214
|
+
stdout: boolean;
|
|
215
|
+
stderr: boolean;
|
|
216
|
+
}
|
|
139
217
|
interface OutputMode {
|
|
140
218
|
format: OutputFormat;
|
|
141
219
|
interactive: boolean;
|
|
142
|
-
color:
|
|
220
|
+
color: StreamColors;
|
|
143
221
|
}
|
|
144
222
|
interface ResolveOutputModeOptions {
|
|
145
223
|
output?: OutputPreference;
|
|
146
224
|
env?: Readonly<Record<string, string | undefined>>;
|
|
147
225
|
inputIsTTY?: boolean;
|
|
148
226
|
outputIsTTY?: boolean;
|
|
227
|
+
errorOutputIsTTY?: boolean;
|
|
149
228
|
}
|
|
150
229
|
/** Resolve output behavior once, before command routing or argument parsing. */
|
|
151
230
|
declare function resolveOutputMode(options?: ResolveOutputModeOptions): OutputMode;
|
|
@@ -199,6 +278,16 @@ interface PromptPrintEvent {
|
|
|
199
278
|
type: "prompt";
|
|
200
279
|
prompt: PromptState;
|
|
201
280
|
}
|
|
281
|
+
/** Command output: exact text written to stdout, or a JSON value. */
|
|
282
|
+
type OutputPrintEvent = {
|
|
283
|
+
type: "output";
|
|
284
|
+
kind: "text";
|
|
285
|
+
text: string;
|
|
286
|
+
} | {
|
|
287
|
+
type: "output";
|
|
288
|
+
kind: "json";
|
|
289
|
+
data: unknown;
|
|
290
|
+
};
|
|
202
291
|
interface ExecPrintEvent {
|
|
203
292
|
type: "exec";
|
|
204
293
|
phase: "start" | "skip";
|
|
@@ -213,7 +302,7 @@ interface ExecPrintEvent {
|
|
|
213
302
|
interactive: boolean;
|
|
214
303
|
}
|
|
215
304
|
/** A semantic, command- and schema-free output value emitted by hacksh. */
|
|
216
|
-
type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | ExecPrintEvent;
|
|
305
|
+
type PrintEvent = UsagePrintEvent | VersionPrintEvent | ErrorPrintEvent | LogPrintEvent | PromptPrintEvent | OutputPrintEvent | ExecPrintEvent;
|
|
217
306
|
/** Receives every output event produced by one command invocation. */
|
|
218
307
|
interface Printer {
|
|
219
308
|
print(event: PrintEvent): void | Promise<void>;
|
|
@@ -242,79 +331,16 @@ interface JsonPrinterOptions {
|
|
|
242
331
|
/** Create a one-semantic-event-per-line JSON printer. */
|
|
243
332
|
declare function createJsonPrinter(options?: JsonPrinterOptions): Printer;
|
|
244
333
|
//#endregion
|
|
245
|
-
//#region src/
|
|
246
|
-
|
|
247
|
-
interface
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
maxBuffer?: number;
|
|
255
|
-
forceKillAfterDelay?: number;
|
|
256
|
-
stdin?: "pipe" | "inherit";
|
|
257
|
-
stdout?: "pipe" | "inherit";
|
|
258
|
-
stderr?: "pipe" | "inherit";
|
|
259
|
-
interactive?: boolean;
|
|
260
|
-
display?: boolean;
|
|
261
|
-
redact?: readonly string[];
|
|
262
|
-
dryRun?: boolean;
|
|
263
|
-
}
|
|
264
|
-
interface ExecCommand {
|
|
265
|
-
file: string;
|
|
266
|
-
args: readonly string[];
|
|
267
|
-
cwd: string | undefined;
|
|
334
|
+
//#region src/command-output.d.ts
|
|
335
|
+
/** Writes a command's results to stdout, separately from logs. */
|
|
336
|
+
interface Output {
|
|
337
|
+
/** Write text exactly as given. */
|
|
338
|
+
print(text: string): void;
|
|
339
|
+
/** Write text followed by a newline. */
|
|
340
|
+
println(text?: string): void;
|
|
341
|
+
/** Write a JSON value. */
|
|
342
|
+
json(value: unknown): void;
|
|
268
343
|
}
|
|
269
|
-
interface ExecSuccess {
|
|
270
|
-
status: "succeeded";
|
|
271
|
-
command: ExecCommand;
|
|
272
|
-
stdout: string;
|
|
273
|
-
stderr: string;
|
|
274
|
-
exitCode: 0;
|
|
275
|
-
}
|
|
276
|
-
type ExecFailure = {
|
|
277
|
-
status: "failed";
|
|
278
|
-
command: ExecCommand;
|
|
279
|
-
stdout: string;
|
|
280
|
-
stderr: string;
|
|
281
|
-
} & ({
|
|
282
|
-
reason: "exit-code";
|
|
283
|
-
exitCode: number;
|
|
284
|
-
} | {
|
|
285
|
-
reason: "signal";
|
|
286
|
-
signal: string;
|
|
287
|
-
} | {
|
|
288
|
-
reason: "spawn";
|
|
289
|
-
error: Error;
|
|
290
|
-
} | {
|
|
291
|
-
reason: "timeout" | "aborted" | "output-limit";
|
|
292
|
-
} | {
|
|
293
|
-
reason: "json-output" | "non-interactive" | "overlapping";
|
|
294
|
-
});
|
|
295
|
-
type ExecFailureReason = ExecFailure["reason"];
|
|
296
|
-
type ExecResult = ExecSuccess | ExecFailure;
|
|
297
|
-
interface ExecSkipped {
|
|
298
|
-
status: "skipped";
|
|
299
|
-
command: ExecCommand;
|
|
300
|
-
}
|
|
301
|
-
type ExecOutcome<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? ExecResult : ExecSuccess : ExecSuccess;
|
|
302
|
-
type SpecifiedDryRun<O> = "dryRun" extends keyof O ? O["dryRun"] : false;
|
|
303
|
-
type ReturnsFailure<O extends ExecOptions> = "reject" extends keyof O ? false extends O["reject"] ? true : false : false;
|
|
304
|
-
type AbortedFailure = {
|
|
305
|
-
status: "failed";
|
|
306
|
-
command: ExecCommand;
|
|
307
|
-
stdout: string;
|
|
308
|
-
stderr: string;
|
|
309
|
-
reason: "aborted";
|
|
310
|
-
};
|
|
311
|
-
type DefiniteSkip<O extends ExecOptions> = ReturnsFailure<O> extends true ? ExecSkipped | AbortedFailure : ExecSkipped;
|
|
312
|
-
type ExecReturn<O extends ExecOptions> = true extends SpecifiedDryRun<O> ? false extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : undefined extends SpecifiedDryRun<O> ? ExecSkipped | ExecOutcome<O> : DefiniteSkip<O> : ExecOutcome<O>;
|
|
313
|
-
type RejectInheritedInput<O> = O extends {
|
|
314
|
-
input: string;
|
|
315
|
-
stdin: "inherit";
|
|
316
|
-
} ? never : unknown;
|
|
317
|
-
type Exec = <const O extends ExecOptions = {}>(file: string, args?: readonly string[], options?: O & { [K in Exclude<keyof O, keyof ExecOptions>]: never; } & RejectInheritedInput<O>) => Promise<ExecReturn<O>>;
|
|
318
344
|
//#endregion
|
|
319
345
|
//#region src/prompts.d.ts
|
|
320
346
|
interface SelectOption<T extends string> {
|
|
@@ -366,6 +392,7 @@ interface CommandContext<S extends ArgsSchema> {
|
|
|
366
392
|
unknown: string[];
|
|
367
393
|
passthrough: string[];
|
|
368
394
|
};
|
|
395
|
+
output: Output;
|
|
369
396
|
logger: Logger;
|
|
370
397
|
prompt: Prompter;
|
|
371
398
|
exec: Exec;
|
|
@@ -385,5 +412,5 @@ interface CommandDef<S extends ArgsSchema = EmptyArgs, R = unknown, Children ext
|
|
|
385
412
|
type AnyCommandDef = CommandDef<ArgsSchema>;
|
|
386
413
|
declare function defineCommand<S extends ArgsSchema = EmptyArgs, R = never, Children extends Record<string, AnyCommandDef> = {}>(def: CommandDef<S, R, Children>): CommandDef<S, NoInfer<R>, NoInfer<Children>>;
|
|
387
414
|
//#endregion
|
|
388
|
-
export {
|
|
389
|
-
//# sourceMappingURL=command-
|
|
415
|
+
export { HackshErrorSummary as $, SelectPromptState as A, UsageArgumentSummary as B, PrintStream as C, PromptState as D, PromptPrintEvent as E, UsagePrintEvent as F, showUsage as G, UsageOptionSummary as H, VersionPrintEvent as I, LogLevel as J, summarizeUsage as K, createJsonPrinter as L, TerminalInput as M, TerminalOutput as N, PromptStatus as O, TextPromptState as P, HackshErrorKind as Q, resolveOutputMode as R, PrintEvent as S, PromptChoiceState as T, UsageSummary as U, UsageCommandSummary as V, renderUsage as W, LogRecord as X, LogProperties as Y, Logger as Z, OutputFormat as _, ExecSkipped as _t, ArgsSchema as a, HackshUsageError as at, OutputPrintEvent as b, SelectOption as c, PromptKind as ct, Output as d, ExecCommand as dt, HackshExecError as et, ConfirmPromptState as f, ExecFailure as ft, LogPrintEvent as g, ExecReturn as gt, JsonPrinterOptions as h, ExecResult as ht, defineCommand as i, HackshPromptErrorReason as it, StreamColors as j, ResolveOutputModeOptions as k, SelectOptions as l, ValidationIssueSummary as lt, ExecPrintEvent as m, ExecOptions as mt, CommandContext as n, HackshIssue as nt, ConfirmOptions as o, HackshValidationError as ot, ErrorPrintEvent as p, ExecFailureReason as pt, LogKind as q, CommandDef as r, HackshPromptError as rt, Prompter as s, PromptErrorDetails as st, AnyCommandDef as t, HackshExitError as tt, TextOptions as u, Exec as ut, OutputMode as v, ExecSuccess as vt, Printer as w, OutputWriter as x, OutputPreference as y, ShowUsageOptions as z };
|
|
416
|
+
//# sourceMappingURL=command-B-Ok_6KW.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as showUsage, K as summarizeUsage, M as TerminalInput, N as TerminalOutput, W as renderUsage, Z as Logger, _t as ExecSkipped, a as ArgsSchema, at as HackshUsageError, c as SelectOption, ct as PromptKind, d as Output, dt as ExecCommand, et as HackshExecError, ft as ExecFailure, gt as ExecReturn, ht as ExecResult, i as defineCommand, it as HackshPromptErrorReason, l as SelectOptions, mt as ExecOptions, n as CommandContext, nt as HackshIssue, o as ConfirmOptions, ot as HackshValidationError, pt as ExecFailureReason, r as CommandDef, rt as HackshPromptError, s as Prompter, st as PromptErrorDetails, t as AnyCommandDef, tt as HackshExitError, u as TextOptions, ut as Exec, vt as ExecSuccess, w as Printer, y as OutputPreference, z as ShowUsageOptions } from "./command-B-Ok_6KW.js";
|
|
2
2
|
import { output } from "zod/v4/core";
|
|
3
3
|
//#region src/parser.d.ts
|
|
4
4
|
/**
|
|
@@ -17,7 +17,7 @@ interface OutputOptions {
|
|
|
17
17
|
env?: Readonly<Record<string, string | undefined>>;
|
|
18
18
|
stdin?: TerminalInput;
|
|
19
19
|
stdout?: TerminalOutput;
|
|
20
|
-
stderr?:
|
|
20
|
+
stderr?: TerminalOutput;
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/run.d.ts
|
|
@@ -39,5 +39,5 @@ interface RunMainOptions extends OutputOptions {
|
|
|
39
39
|
}
|
|
40
40
|
declare function runMain<S extends ArgsSchema>(command: CommandDef<S>, options?: RunMainOptions): Promise<void>;
|
|
41
41
|
//#endregion
|
|
42
|
-
export { type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
42
|
+
export { type CommandContext, type CommandDef, type ConfirmOptions, type Exec, type ExecCommand, type ExecFailure, type ExecFailureReason, type ExecOptions, type ExecResult, type ExecReturn, type ExecSkipped, type ExecSuccess, HackshExecError, HackshExitError, type HackshIssue, HackshPromptError, type HackshPromptErrorReason, HackshUsageError, HackshValidationError, type Logger, type Output, type OutputOptions, type PromptErrorDetails, type PromptKind, type Prompter, type RunCommandOptions, type RunMainOptions, type SelectOption, type SelectOptions, type ShowUsageOptions, type TextOptions, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage, summarizeUsage };
|
|
43
43
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createExec, c as HackshPromptError, d as summarizeError, f as summarizeErrors, i as resolveOutputMode, l as HackshUsageError, n as createJsonPrinter, o as HackshExecError, r as createPrintQueue, s as HackshExitError, t as createPrettyPrinter, u as HackshValidationError } from "./pretty-
|
|
1
|
+
import { a as createExec, c as HackshPromptError, d as summarizeError, f as summarizeErrors, i as resolveOutputMode, l as HackshUsageError, n as createJsonPrinter, o as HackshExecError, r as createPrintQueue, s as HackshExitError, t as createPrettyPrinter, u as HackshValidationError } from "./pretty-DJ2CE6TU.js";
|
|
2
2
|
import { globalRegistry, safeParseAsync } from "zod/v4/core";
|
|
3
3
|
import { parseArgs as parseArgs$1 } from "node:util";
|
|
4
4
|
import { readFile, realpath } from "node:fs/promises";
|
|
@@ -475,6 +475,27 @@ async function parseArgs(command, argv, options) {
|
|
|
475
475
|
return (await parseCommandArgs(command, argv, tokenizeCommandArgs(command, argv), options?.env, envPath)).args;
|
|
476
476
|
}
|
|
477
477
|
//#endregion
|
|
478
|
+
//#region src/command-output.ts
|
|
479
|
+
/** Create the output for one command invocation. */
|
|
480
|
+
function createOutput(printer) {
|
|
481
|
+
function print(text) {
|
|
482
|
+
printer.print({
|
|
483
|
+
type: "output",
|
|
484
|
+
kind: "text",
|
|
485
|
+
text
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
print,
|
|
490
|
+
println: (text = "") => print(`${text}\n`),
|
|
491
|
+
json: (data) => void printer.print({
|
|
492
|
+
type: "output",
|
|
493
|
+
kind: "json",
|
|
494
|
+
data
|
|
495
|
+
})
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
478
499
|
//#region src/terminal.ts
|
|
479
500
|
var TerminalLock = class {
|
|
480
501
|
#owner;
|
|
@@ -885,7 +906,8 @@ function selectOutputPrinter(options, override, resolvedMode) {
|
|
|
885
906
|
output: options.output,
|
|
886
907
|
env: options.env,
|
|
887
908
|
inputIsTTY: stdin.isTTY,
|
|
888
|
-
outputIsTTY: stdout.isTTY
|
|
909
|
+
outputIsTTY: stdout.isTTY,
|
|
910
|
+
errorOutputIsTTY: stderr.isTTY
|
|
889
911
|
});
|
|
890
912
|
if (override) return override;
|
|
891
913
|
if (mode.format === "json") return createJsonPrinter({
|
|
@@ -1109,6 +1131,7 @@ async function executeCommand(root, argv, output, env, signal, fallbackVersion =
|
|
|
1109
1131
|
unknown: parsed.extraArgs,
|
|
1110
1132
|
passthrough: parsed.passthrough
|
|
1111
1133
|
},
|
|
1134
|
+
output: createOutput(printer),
|
|
1112
1135
|
logger: createLogger(printer, category),
|
|
1113
1136
|
prompt: new PromptController({
|
|
1114
1137
|
interactive: output.interactive,
|
|
@@ -1136,7 +1159,8 @@ function prepareOutput(options, env) {
|
|
|
1136
1159
|
output: options.output,
|
|
1137
1160
|
env,
|
|
1138
1161
|
inputIsTTY: input.isTTY,
|
|
1139
|
-
outputIsTTY: (options.stdout ?? process.stdout).isTTY
|
|
1162
|
+
outputIsTTY: (options.stdout ?? process.stdout).isTTY,
|
|
1163
|
+
errorOutputIsTTY: (options.stderr ?? process.stderr).isTTY
|
|
1140
1164
|
});
|
|
1141
1165
|
return {
|
|
1142
1166
|
...createPrintQueue(selectOutputPrinter(options, options.printer, mode)),
|