@optique/run 1.0.0-dev.432 → 1.0.0-dev.438

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/dist/run.cjs CHANGED
@@ -55,8 +55,12 @@ function runAsync(parserOrProgram, options = {}) {
55
55
  * @internal
56
56
  */
57
57
  function buildCoreOptions(options, programMetadata) {
58
- const { programName = node_path.default.basename(node_process.default.argv[1] || "cli"), args = node_process.default.argv.slice(2), colors = node_process.default.stdout.isTTY, maxWidth = node_process.default.stdout.columns, showDefault, showChoices, sectionOrder, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
59
- const onShow = () => node_process.default.exit(0);
58
+ const { programName = node_path.default.basename(node_process.default.argv[1] || "cli"), args = node_process.default.argv.slice(2), stdout = (line) => {
59
+ node_process.default.stdout.write(`${line}\n`);
60
+ }, stderr = (line) => {
61
+ node_process.default.stderr.write(`${line}\n`);
62
+ }, onExit = (exitCode) => node_process.default.exit(exitCode), colors = node_process.default.stdout.isTTY, maxWidth = node_process.default.stdout.columns, showDefault, showChoices, sectionOrder, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
63
+ const onShow = () => onExit(0);
60
64
  const helpConfig = (() => {
61
65
  if (!help) return void 0;
62
66
  if (typeof help === "string") switch (help) {
@@ -114,12 +118,8 @@ function buildCoreOptions(options, programMetadata) {
114
118
  };
115
119
  })();
116
120
  const coreOptions = {
117
- stderr(line) {
118
- node_process.default.stderr.write(`${line}\n`);
119
- },
120
- stdout(line) {
121
- node_process.default.stdout.write(`${line}\n`);
122
- },
121
+ stderr,
122
+ stdout,
123
123
  colors,
124
124
  maxWidth,
125
125
  showDefault,
@@ -136,7 +136,7 @@ function buildCoreOptions(options, programMetadata) {
136
136
  bugs,
137
137
  footer,
138
138
  onError() {
139
- return node_process.default.exit(errorExitCode);
139
+ return onExit(errorExitCode);
140
140
  }
141
141
  };
142
142
  return {
@@ -152,6 +152,9 @@ function buildCoreOptions(options, programMetadata) {
152
152
  const knownRunOptionsKeys = new Set([
153
153
  "programName",
154
154
  "args",
155
+ "stdout",
156
+ "stderr",
157
+ "onExit",
155
158
  "colors",
156
159
  "maxWidth",
157
160
  "showDefault",
package/dist/run.d.cts CHANGED
@@ -24,6 +24,26 @@ interface RunOptions {
24
24
  * @default `process.argv.slice(2)` (arguments after the script name)
25
25
  */
26
26
  readonly args?: readonly string[];
27
+ /**
28
+ * Function used to output help and usage messages. Assumes it prints the
29
+ * ending newline.
30
+ *
31
+ * @default Writes to `process.stdout` with a trailing newline
32
+ */
33
+ readonly stdout?: (text: string) => void;
34
+ /**
35
+ * Function used to output error messages. Assumes it prints the ending
36
+ * newline.
37
+ *
38
+ * @default Writes to `process.stderr` with a trailing newline
39
+ */
40
+ readonly stderr?: (text: string) => void;
41
+ /**
42
+ * Function used to exit the process on help/version display or parse error.
43
+ *
44
+ * @default `process.exit`
45
+ */
46
+ readonly onExit?: (exitCode: number) => never;
27
47
  /**
28
48
  * Whether to enable colored output in help and error messages.
29
49
  *
package/dist/run.d.ts CHANGED
@@ -24,6 +24,26 @@ interface RunOptions {
24
24
  * @default `process.argv.slice(2)` (arguments after the script name)
25
25
  */
26
26
  readonly args?: readonly string[];
27
+ /**
28
+ * Function used to output help and usage messages. Assumes it prints the
29
+ * ending newline.
30
+ *
31
+ * @default Writes to `process.stdout` with a trailing newline
32
+ */
33
+ readonly stdout?: (text: string) => void;
34
+ /**
35
+ * Function used to output error messages. Assumes it prints the ending
36
+ * newline.
37
+ *
38
+ * @default Writes to `process.stderr` with a trailing newline
39
+ */
40
+ readonly stderr?: (text: string) => void;
41
+ /**
42
+ * Function used to exit the process on help/version display or parse error.
43
+ *
44
+ * @default `process.exit`
45
+ */
46
+ readonly onExit?: (exitCode: number) => never;
27
47
  /**
28
48
  * Whether to enable colored output in help and error messages.
29
49
  *
package/dist/run.js CHANGED
@@ -54,8 +54,12 @@ function runAsync(parserOrProgram, options = {}) {
54
54
  * @internal
55
55
  */
56
56
  function buildCoreOptions(options, programMetadata) {
57
- const { programName = path.basename(process.argv[1] || "cli"), args = process.argv.slice(2), colors = process.stdout.isTTY, maxWidth = process.stdout.columns, showDefault, showChoices, sectionOrder, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
58
- const onShow = () => process.exit(0);
57
+ const { programName = path.basename(process.argv[1] || "cli"), args = process.argv.slice(2), stdout = (line) => {
58
+ process.stdout.write(`${line}\n`);
59
+ }, stderr = (line) => {
60
+ process.stderr.write(`${line}\n`);
61
+ }, onExit = (exitCode) => process.exit(exitCode), colors = process.stdout.isTTY, maxWidth = process.stdout.columns, showDefault, showChoices, sectionOrder, help, version, completion, aboveError = "usage", errorExitCode = 1, brief = programMetadata?.brief, description = programMetadata?.description, examples = programMetadata?.examples, author = programMetadata?.author, bugs = programMetadata?.bugs, footer = programMetadata?.footer } = options;
62
+ const onShow = () => onExit(0);
59
63
  const helpConfig = (() => {
60
64
  if (!help) return void 0;
61
65
  if (typeof help === "string") switch (help) {
@@ -113,12 +117,8 @@ function buildCoreOptions(options, programMetadata) {
113
117
  };
114
118
  })();
115
119
  const coreOptions = {
116
- stderr(line) {
117
- process.stderr.write(`${line}\n`);
118
- },
119
- stdout(line) {
120
- process.stdout.write(`${line}\n`);
121
- },
120
+ stderr,
121
+ stdout,
122
122
  colors,
123
123
  maxWidth,
124
124
  showDefault,
@@ -135,7 +135,7 @@ function buildCoreOptions(options, programMetadata) {
135
135
  bugs,
136
136
  footer,
137
137
  onError() {
138
- return process.exit(errorExitCode);
138
+ return onExit(errorExitCode);
139
139
  }
140
140
  };
141
141
  return {
@@ -151,6 +151,9 @@ function buildCoreOptions(options, programMetadata) {
151
151
  const knownRunOptionsKeys = new Set([
152
152
  "programName",
153
153
  "args",
154
+ "stdout",
155
+ "stderr",
156
+ "onExit",
154
157
  "colors",
155
158
  "maxWidth",
156
159
  "showDefault",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/run",
3
- "version": "1.0.0-dev.432+dddcca3d",
3
+ "version": "1.0.0-dev.438+923a6492",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "sideEffects": false,
72
72
  "dependencies": {
73
- "@optique/core": "1.0.0-dev.432+dddcca3d"
73
+ "@optique/core": "1.0.0-dev.438+923a6492"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^20.19.9",