@rune-cli/rune 0.0.8 → 0.0.9

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/cli.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import "./dist-uz53Uv1e.mjs";
3
- import { n as isHelpFlag, r as isVersionFlag, t as runManifestCommand } from "./run-manifest-command-Dq_lBv-H.mjs";
2
+ import "./dist-DuisScgY.mjs";
3
+ import { n as isHelpFlag, r as isVersionFlag, t as runManifestCommand } from "./run-manifest-command-BphalAwU.mjs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { build } from "esbuild";
6
6
  import { cp, mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import ts from "typescript";
9
9
  //#region package.json
10
- var version = "0.0.8";
10
+ var version = "0.0.9";
11
11
  //#endregion
12
12
  //#region src/manifest/generate-manifest.ts
13
13
  const COMMAND_ENTRY_FILE = "index.ts";
@@ -94,7 +94,9 @@ async function walkCommandsDirectory(absoluteDirectoryPath, pathSegments, extrac
94
94
  }
95
95
  async function generateCommandManifest(options) {
96
96
  const extractDescription = options.extractDescription ?? extractDescriptionFromSourceFile;
97
- return { nodes: [...(await walkCommandsDirectory(options.commandsDirectory, [], extractDescription)).nodes].sort((left, right) => comparePathSegments(left.pathSegments, right.pathSegments)) };
97
+ const walkResult = await walkCommandsDirectory(options.commandsDirectory, [], extractDescription);
98
+ if (walkResult.nodes.length === 0) throw new Error("No commands found in src/commands/. Create a command file like src/commands/hello/index.ts");
99
+ return { nodes: [...walkResult.nodes].sort((left, right) => comparePathSegments(left.pathSegments, right.pathSegments)) };
98
100
  }
99
101
  function serializeCommandManifest(manifest) {
100
102
  return JSON.stringify(manifest, null, 2);
@@ -97,6 +97,7 @@ function validateArgOrdering(args) {
97
97
  * the ordering check is skipped for that field.
98
98
  */
99
99
  function defineCommand(input) {
100
+ if (typeof input.run !== "function") throw new Error("defineCommand() requires a \"run\" function.");
100
101
  if (input.args) {
101
102
  validateFieldShape(input.args, "argument");
102
103
  validateUniqueFieldNames(input.args, "argument");
@@ -212,60 +213,48 @@ function formatOptionLabel(field) {
212
213
  function formatArgumentLabel(field) {
213
214
  return field.name;
214
215
  }
215
- function missingRequiredOption(field) {
216
+ function createMissingOptionError(field) {
216
217
  return {
217
218
  ok: false,
218
219
  error: { message: `Missing required option:\n\n ${formatOptionLabel(field)}` }
219
220
  };
220
221
  }
221
- function missingRequiredArgument(field) {
222
+ function createMissingArgumentError(field) {
222
223
  return {
223
224
  ok: false,
224
225
  error: { message: `Missing required argument:\n\n ${formatArgumentLabel(field)}` }
225
226
  };
226
227
  }
227
- function invalidOptionValue(field, messages) {
228
+ function createInvalidOptionError(field, messages) {
228
229
  return {
229
230
  ok: false,
230
231
  error: { message: `Invalid value for option ${formatOptionLabel(field)}:\n\n ${messages.join("\n ")}` }
231
232
  };
232
233
  }
233
- function invalidArgumentValue(field, messages) {
234
+ function createInvalidArgumentError(field, messages) {
234
235
  return {
235
236
  ok: false,
236
237
  error: { message: `Invalid value for argument ${formatArgumentLabel(field)}:\n\n ${messages.join("\n ")}` }
237
238
  };
238
239
  }
239
- function unknownOption(token) {
240
+ function createUnknownOptionError(token) {
240
241
  return {
241
242
  ok: false,
242
243
  error: { message: `Unknown option "${token}"` }
243
244
  };
244
245
  }
245
- function duplicateOption(field) {
246
+ function createDuplicateOptionError(field) {
246
247
  return {
247
248
  ok: false,
248
249
  error: { message: `Duplicate option "${formatOptionLabel(field)}" is not supported` }
249
250
  };
250
251
  }
251
- function unexpectedArgument(token) {
252
+ function createUnexpectedArgumentError(token) {
252
253
  return {
253
254
  ok: false,
254
255
  error: { message: `Unexpected argument "${token}"` }
255
256
  };
256
257
  }
257
- function normalizeParseArgsError(error) {
258
- if (!(error instanceof Error)) return {
259
- ok: false,
260
- error: { message: "Argument parsing failed" }
261
- };
262
- const unknownMatch = error.message.match(/Unknown option '([^']+)'/);
263
- if (unknownMatch) return unknownOption(unknownMatch[1]);
264
- return {
265
- ok: false,
266
- error: { message: error.message }
267
- };
268
- }
269
258
  function parsePrimitiveValue(field, rawValue) {
270
259
  if (isSchemaField(field)) throw new Error("Schema fields must be handled separately");
271
260
  switch (field.type) {
@@ -352,9 +341,9 @@ async function resolveMissingField(field, missingRequired) {
352
341
  };
353
342
  }
354
343
  async function parseArgumentField(field, rawValue) {
355
- if (rawValue === void 0) return resolveMissingField(field, () => missingRequiredArgument(field));
344
+ if (rawValue === void 0) return resolveMissingField(field, () => createMissingArgumentError(field));
356
345
  const result = await parseProvidedField(field, rawValue);
357
- if (!result.ok) return invalidArgumentValue(field, result.error.message.split("\n"));
346
+ if (!result.ok) return createInvalidArgumentError(field, result.error.message.split("\n"));
358
347
  return {
359
348
  ok: true,
360
349
  present: true,
@@ -363,13 +352,25 @@ async function parseArgumentField(field, rawValue) {
363
352
  }
364
353
  async function parseOptionField(field, rawValue) {
365
354
  const result = await parseProvidedField(field, rawValue);
366
- if (!result.ok) return invalidOptionValue(field, result.error.message.split("\n"));
355
+ if (!result.ok) return createInvalidOptionError(field, result.error.message.split("\n"));
367
356
  return {
368
357
  ok: true,
369
358
  present: true,
370
359
  value: result.value
371
360
  };
372
361
  }
362
+ function normalizeParseArgsError(error) {
363
+ if (!(error instanceof Error)) return {
364
+ ok: false,
365
+ error: { message: "Argument parsing failed" }
366
+ };
367
+ const unknownMatch = error.message.match(/Unknown option '([^']+)'/);
368
+ if (unknownMatch) return createUnknownOptionError(unknownMatch[1]);
369
+ return {
370
+ ok: false,
371
+ error: { message: error.message }
372
+ };
373
+ }
373
374
  function getOptionParseType(field) {
374
375
  if (isSchemaField(field)) return field.flag ? "boolean" : "string";
375
376
  return field.type === "boolean" ? "boolean" : "string";
@@ -390,7 +391,7 @@ function detectDuplicateOption(options, tokens) {
390
391
  counts.set(token.name, nextCount);
391
392
  if (nextCount > 1) {
392
393
  const field = options.find((option) => option.name === token.name);
393
- if (field) return duplicateOption(field);
394
+ if (field) return createDuplicateOptionError(field);
394
395
  }
395
396
  }
396
397
  }
@@ -417,7 +418,7 @@ async function parseCommand(command, rawArgs) {
417
418
  if (!result.ok) return result;
418
419
  if (result.present) parsedArgs[field.name] = result.value;
419
420
  }
420
- if (parsed.positionals.length > command.args.length) return unexpectedArgument(parsed.positionals[command.args.length]);
421
+ if (parsed.positionals.length > command.args.length) return createUnexpectedArgumentError(parsed.positionals[command.args.length]);
421
422
  for (const field of command.options) {
422
423
  const rawValue = parsed.values[field.name];
423
424
  if (rawValue !== void 0) {
@@ -426,7 +427,7 @@ async function parseCommand(command, rawArgs) {
426
427
  if (result.present) parsedOptions[field.name] = result.value;
427
428
  continue;
428
429
  }
429
- const result = await resolveMissingField(field, () => missingRequiredOption(field));
430
+ const result = await resolveMissingField(field, () => createMissingOptionError(field));
430
431
  if (!result.ok) return result;
431
432
  if (result.present) parsedOptions[field.name] = result.value;
432
433
  else if (!isSchemaField(field) && field.type === "boolean") parsedOptions[field.name] = false;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as defineCommand } from "./dist-uz53Uv1e.mjs";
1
+ import { n as defineCommand } from "./dist-DuisScgY.mjs";
2
2
  export { defineCommand };
@@ -1,4 +1,4 @@
1
- import { a as isSchemaField, i as isDefinedCommand, o as parseCommand, r as executeCommand } from "./dist-uz53Uv1e.mjs";
1
+ import { a as isSchemaField, i as isDefinedCommand, o as parseCommand, r as executeCommand } from "./dist-DuisScgY.mjs";
2
2
  import { pathToFileURL } from "node:url";
3
3
  //#region src/cli/flags.ts
4
4
  function isHelpFlag(token) {
package/dist/runtime.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import "./dist-uz53Uv1e.mjs";
2
- import { t as runManifestCommand } from "./run-manifest-command-Dq_lBv-H.mjs";
1
+ import "./dist-DuisScgY.mjs";
2
+ import { t as runManifestCommand } from "./run-manifest-command-BphalAwU.mjs";
3
3
  export { runManifestCommand };
package/dist/test.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as executeCommand, t as captureProcessOutput } from "./dist-uz53Uv1e.mjs";
1
+ import { r as executeCommand, t as captureProcessOutput } from "./dist-DuisScgY.mjs";
2
2
  //#region src/test.ts
3
3
  /**
4
4
  * Runs a command definition directly in-process for testing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rune-cli/rune",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Rune is a CLI framework built around the concept of file-based command routing.",
5
5
  "homepage": "https://github.com/morinokami/rune#readme",
6
6
  "bugs": {