citty 0.1.4 → 0.1.5

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 CHANGED
@@ -88,7 +88,7 @@ Create a wrapper around command that calls `runMain` when called.
88
88
 
89
89
  ### `runCommand`
90
90
 
91
- Parses input args and runs command and sub-commands (unsupervised).
91
+ Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returnd/awaited value to access command's result.
92
92
 
93
93
  ### `parseArgs`
94
94
 
package/dist/index.cjs CHANGED
@@ -293,6 +293,7 @@ async function runCommand(cmd, opts) {
293
293
  if (typeof cmd.setup === "function") {
294
294
  await cmd.setup(context);
295
295
  }
296
+ let result;
296
297
  try {
297
298
  const subCommands = await resolveValue(cmd.subCommands);
298
299
  if (subCommands && Object.keys(subCommands).length > 0) {
@@ -318,13 +319,14 @@ async function runCommand(cmd, opts) {
318
319
  }
319
320
  }
320
321
  if (typeof cmd.run === "function") {
321
- await cmd.run(context);
322
+ result = await cmd.run(context);
322
323
  }
323
324
  } finally {
324
325
  if (typeof cmd.cleanup === "function") {
325
326
  await cmd.cleanup(context);
326
327
  }
327
328
  }
329
+ return { result };
328
330
  }
329
331
  async function resolveSubCommand(cmd, rawArgs, parent) {
330
332
  const subCommands = await resolveValue(cmd.subCommands);
@@ -430,9 +432,10 @@ async function renderUsage(cmd, parent) {
430
432
 
431
433
  async function runMain(cmd, opts = {}) {
432
434
  const rawArgs = opts.rawArgs || process.argv.slice(2);
435
+ const showUsage$1 = opts.showUsage || showUsage;
433
436
  try {
434
437
  if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
435
- await showUsage(...await resolveSubCommand(cmd, rawArgs));
438
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
436
439
  process.exit(0);
437
440
  } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
438
441
  const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
@@ -449,7 +452,7 @@ async function runMain(cmd, opts = {}) {
449
452
  consola__default.error(error, "\n");
450
453
  }
451
454
  if (isCLIError) {
452
- await showUsage(...await resolveSubCommand(cmd, rawArgs));
455
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
453
456
  }
454
457
  consola__default.error(error.message);
455
458
  process.exit(1);
package/dist/index.d.cts CHANGED
@@ -61,17 +61,20 @@ interface RunCommandOptions {
61
61
  data?: any;
62
62
  showUsage?: boolean;
63
63
  }
64
- declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<void>;
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
65
70
 
66
71
  interface RunMainOptions {
67
72
  rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
68
74
  }
69
75
  declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
70
76
  declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
71
77
 
72
78
  declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
73
79
 
74
- declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
75
- declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
76
-
77
80
  export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
package/dist/index.d.mts CHANGED
@@ -61,17 +61,20 @@ interface RunCommandOptions {
61
61
  data?: any;
62
62
  showUsage?: boolean;
63
63
  }
64
- declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<void>;
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
65
70
 
66
71
  interface RunMainOptions {
67
72
  rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
68
74
  }
69
75
  declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
70
76
  declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
71
77
 
72
78
  declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
73
79
 
74
- declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
75
- declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
76
-
77
80
  export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
package/dist/index.d.ts CHANGED
@@ -61,17 +61,20 @@ interface RunCommandOptions {
61
61
  data?: any;
62
62
  showUsage?: boolean;
63
63
  }
64
- declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<void>;
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
65
70
 
66
71
  interface RunMainOptions {
67
72
  rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
68
74
  }
69
75
  declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
70
76
  declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
71
77
 
72
78
  declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
73
79
 
74
- declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
75
- declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
76
-
77
80
  export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
package/dist/index.mjs CHANGED
@@ -287,6 +287,7 @@ async function runCommand(cmd, opts) {
287
287
  if (typeof cmd.setup === "function") {
288
288
  await cmd.setup(context);
289
289
  }
290
+ let result;
290
291
  try {
291
292
  const subCommands = await resolveValue(cmd.subCommands);
292
293
  if (subCommands && Object.keys(subCommands).length > 0) {
@@ -312,13 +313,14 @@ async function runCommand(cmd, opts) {
312
313
  }
313
314
  }
314
315
  if (typeof cmd.run === "function") {
315
- await cmd.run(context);
316
+ result = await cmd.run(context);
316
317
  }
317
318
  } finally {
318
319
  if (typeof cmd.cleanup === "function") {
319
320
  await cmd.cleanup(context);
320
321
  }
321
322
  }
323
+ return { result };
322
324
  }
323
325
  async function resolveSubCommand(cmd, rawArgs, parent) {
324
326
  const subCommands = await resolveValue(cmd.subCommands);
@@ -424,9 +426,10 @@ async function renderUsage(cmd, parent) {
424
426
 
425
427
  async function runMain(cmd, opts = {}) {
426
428
  const rawArgs = opts.rawArgs || process.argv.slice(2);
429
+ const showUsage$1 = opts.showUsage || showUsage;
427
430
  try {
428
431
  if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
429
- await showUsage(...await resolveSubCommand(cmd, rawArgs));
432
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
430
433
  process.exit(0);
431
434
  } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
432
435
  const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
@@ -443,7 +446,7 @@ async function runMain(cmd, opts = {}) {
443
446
  consola.error(error, "\n");
444
447
  }
445
448
  if (isCLIError) {
446
- await showUsage(...await resolveSubCommand(cmd, rawArgs));
449
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
447
450
  }
448
451
  consola.error(error.message);
449
452
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "citty",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Elegant CLI Builder",
5
5
  "repository": "unjs/citty",
6
6
  "license": "MIT",
@@ -33,17 +33,17 @@
33
33
  "consola": "^3.2.3"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "^20.6.0",
37
- "@vitest/coverage-v8": "^0.34.4",
36
+ "@types/node": "^20.9.0",
37
+ "@vitest/coverage-v8": "^0.34.6",
38
38
  "changelogen": "^0.5.5",
39
- "eslint": "^8.49.0",
39
+ "eslint": "^8.53.0",
40
40
  "eslint-config-unjs": "^0.2.1",
41
- "jiti": "^1.20.0",
42
- "prettier": "^3.0.3",
41
+ "jiti": "^1.21.0",
42
+ "prettier": "^3.1.0",
43
43
  "scule": "^1.0.0",
44
44
  "typescript": "^5.2.2",
45
45
  "unbuild": "^2.0.0",
46
- "vitest": "^0.34.4"
46
+ "vitest": "^0.34.6"
47
47
  },
48
- "packageManager": "pnpm@8.7.4"
48
+ "packageManager": "pnpm@8.10.3"
49
49
  }