bob-core 1.2.2 → 1.2.4

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.
Files changed (99) hide show
  1. package/dist/bob-core.cjs +8 -0
  2. package/dist/bob-core.js +515 -0
  3. package/dist/package-B3ICsvyj.js +27 -0
  4. package/dist/package-sv16L6xn.cjs +1 -0
  5. package/dist/{cjs → types}/src/Cli.d.ts +4 -4
  6. package/dist/{esm → types}/src/Command.d.ts +2 -2
  7. package/dist/{cjs → types}/src/CommandParser.d.ts +1 -1
  8. package/dist/{cjs → types}/src/CommandRegistry.d.ts +1 -1
  9. package/dist/{cjs → types}/src/ExceptionHandler.d.ts +1 -1
  10. package/dist/{esm → types}/src/commands/HelpCommand.d.ts +2 -2
  11. package/dist/{esm → types}/src/errors/BadCommandOption.d.ts +1 -1
  12. package/dist/{cjs → types}/src/errors/BadCommandParameter.d.ts +1 -1
  13. package/dist/{cjs → types}/src/errors/CommandNotFoundError.d.ts +1 -1
  14. package/dist/{esm → types}/src/errors/InvalidOption.d.ts +2 -2
  15. package/dist/{cjs → types}/src/errors/MissingRequiredArgumentValue.d.ts +2 -2
  16. package/dist/{cjs → types}/src/errors/MissingSignatureArgument.d.ts +2 -2
  17. package/dist/{cjs → types}/src/errors/MissingSignatureOption.d.ts +2 -2
  18. package/dist/{cjs → types}/src/options/HelpOption.d.ts +2 -2
  19. package/package.json +12 -20
  20. package/dist/cjs/package.json +0 -1
  21. package/dist/cjs/src/Cli.js +0 -66
  22. package/dist/cjs/src/Command.d.ts +0 -34
  23. package/dist/cjs/src/Command.js +0 -97
  24. package/dist/cjs/src/Command.test.d.ts +0 -1
  25. package/dist/cjs/src/Command.test.js +0 -52
  26. package/dist/cjs/src/CommandParser.js +0 -239
  27. package/dist/cjs/src/CommandParser.test.d.ts +0 -1
  28. package/dist/cjs/src/CommandParser.test.js +0 -177
  29. package/dist/cjs/src/CommandRegistry.js +0 -149
  30. package/dist/cjs/src/ExceptionHandler.js +0 -14
  31. package/dist/cjs/src/commands/HelpCommand.d.ts +0 -14
  32. package/dist/cjs/src/commands/HelpCommand.js +0 -90
  33. package/dist/cjs/src/contracts/CommandOption.js +0 -2
  34. package/dist/cjs/src/contracts/index.js +0 -17
  35. package/dist/cjs/src/errors/BadCommandOption.d.ts +0 -11
  36. package/dist/cjs/src/errors/BadCommandOption.js +0 -36
  37. package/dist/cjs/src/errors/BadCommandParameter.js +0 -36
  38. package/dist/cjs/src/errors/BobError.js +0 -6
  39. package/dist/cjs/src/errors/CommandNotFoundError.js +0 -30
  40. package/dist/cjs/src/errors/InvalidOption.d.ts +0 -8
  41. package/dist/cjs/src/errors/InvalidOption.js +0 -32
  42. package/dist/cjs/src/errors/MissingRequiredArgumentValue.js +0 -23
  43. package/dist/cjs/src/errors/MissingSignatureArgument.js +0 -31
  44. package/dist/cjs/src/errors/MissingSignatureOption.js +0 -31
  45. package/dist/cjs/src/errors/index.js +0 -19
  46. package/dist/cjs/src/index.js +0 -21
  47. package/dist/cjs/src/lib/string.js +0 -6
  48. package/dist/cjs/src/options/HelpOption.js +0 -77
  49. package/dist/cjs/src/options/index.js +0 -17
  50. package/dist/esm/package.json +0 -50
  51. package/dist/esm/src/Cli.d.ts +0 -26
  52. package/dist/esm/src/Cli.js +0 -59
  53. package/dist/esm/src/Command.js +0 -93
  54. package/dist/esm/src/Command.test.d.ts +0 -1
  55. package/dist/esm/src/Command.test.js +0 -50
  56. package/dist/esm/src/CommandParser.d.ts +0 -46
  57. package/dist/esm/src/CommandParser.js +0 -232
  58. package/dist/esm/src/CommandParser.test.d.ts +0 -1
  59. package/dist/esm/src/CommandParser.test.js +0 -175
  60. package/dist/esm/src/CommandRegistry.d.ts +0 -17
  61. package/dist/esm/src/CommandRegistry.js +0 -109
  62. package/dist/esm/src/ExceptionHandler.d.ts +0 -4
  63. package/dist/esm/src/ExceptionHandler.js +0 -10
  64. package/dist/esm/src/commands/HelpCommand.js +0 -51
  65. package/dist/esm/src/contracts/CommandOption.d.ts +0 -7
  66. package/dist/esm/src/contracts/CommandOption.js +0 -1
  67. package/dist/esm/src/contracts/index.d.ts +0 -1
  68. package/dist/esm/src/contracts/index.js +0 -1
  69. package/dist/esm/src/errors/BadCommandOption.js +0 -29
  70. package/dist/esm/src/errors/BadCommandParameter.d.ts +0 -11
  71. package/dist/esm/src/errors/BadCommandParameter.js +0 -29
  72. package/dist/esm/src/errors/BobError.d.ts +0 -3
  73. package/dist/esm/src/errors/BobError.js +0 -2
  74. package/dist/esm/src/errors/CommandNotFoundError.d.ts +0 -7
  75. package/dist/esm/src/errors/CommandNotFoundError.js +0 -23
  76. package/dist/esm/src/errors/InvalidOption.js +0 -25
  77. package/dist/esm/src/errors/MissingRequiredArgumentValue.d.ts +0 -7
  78. package/dist/esm/src/errors/MissingRequiredArgumentValue.js +0 -16
  79. package/dist/esm/src/errors/MissingSignatureArgument.d.ts +0 -8
  80. package/dist/esm/src/errors/MissingSignatureArgument.js +0 -24
  81. package/dist/esm/src/errors/MissingSignatureOption.d.ts +0 -8
  82. package/dist/esm/src/errors/MissingSignatureOption.js +0 -24
  83. package/dist/esm/src/errors/index.d.ts +0 -3
  84. package/dist/esm/src/errors/index.js +0 -3
  85. package/dist/esm/src/index.d.ts +0 -5
  86. package/dist/esm/src/index.js +0 -5
  87. package/dist/esm/src/lib/string.d.ts +0 -1
  88. package/dist/esm/src/lib/string.js +0 -3
  89. package/dist/esm/src/options/HelpOption.d.ts +0 -9
  90. package/dist/esm/src/options/HelpOption.js +0 -70
  91. package/dist/esm/src/options/index.d.ts +0 -1
  92. package/dist/esm/src/options/index.js +0 -1
  93. /package/dist/{cjs → types}/src/contracts/CommandOption.d.ts +0 -0
  94. /package/dist/{cjs → types}/src/contracts/index.d.ts +0 -0
  95. /package/dist/{cjs → types}/src/errors/BobError.d.ts +0 -0
  96. /package/dist/{cjs → types}/src/errors/index.d.ts +0 -0
  97. /package/dist/{cjs → types}/src/index.d.ts +0 -0
  98. /package/dist/{cjs → types}/src/lib/string.d.ts +0 -0
  99. /package/dist/{cjs → types}/src/options/index.d.ts +0 -0
@@ -1,29 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class BadCommandParameter extends BobError {
4
- param;
5
- constructor(param) {
6
- let message = `Argument "${param.param}" value is invalid.`;
7
- if (param.reason) {
8
- message += ` Reason: ${param.reason}`;
9
- }
10
- else {
11
- message += ` Value: "${param.value}"`;
12
- }
13
- super(message);
14
- this.param = param;
15
- }
16
- pretty() {
17
- const log = console.log;
18
- log(chalk ` {white.bgRed ERROR } Argument {bold.yellow ${this.param.param}} value is invalid. `);
19
- if (this.param.value || this.param.reason) {
20
- log('');
21
- }
22
- if (this.param.value) {
23
- log(chalk ` {blue Value}: ${this.param.value}`);
24
- }
25
- if (this.param.reason) {
26
- log(chalk ` {yellow Reason}: ${this.param.reason}`);
27
- }
28
- }
29
- }
@@ -1,3 +0,0 @@
1
- export declare abstract class BobError extends Error {
2
- abstract pretty(): void;
3
- }
@@ -1,2 +0,0 @@
1
- export class BobError extends Error {
2
- }
@@ -1,7 +0,0 @@
1
- import { BobError } from "../errors/BobError.js";
2
- export declare class CommandNotFoundError extends BobError {
3
- readonly command: string;
4
- readonly similarCommands: string[];
5
- constructor(command: string, similarCommands: string[]);
6
- pretty(): void;
7
- }
@@ -1,23 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class CommandNotFoundError extends BobError {
4
- command;
5
- similarCommands;
6
- constructor(command, similarCommands) {
7
- super(`Command "${command}" not found.`);
8
- this.command = command;
9
- this.similarCommands = similarCommands;
10
- }
11
- pretty() {
12
- const log = console.log;
13
- if (this.similarCommands.length) {
14
- log(chalk ` {white.bgRed ERROR } Command "${this.command}" not found, Did you mean one of these?`);
15
- for (const cmd of this.similarCommands) {
16
- log(chalk ` {gray ⇂ ${cmd}}`);
17
- }
18
- }
19
- else {
20
- log(chalk ` {white.bgRed ERROR } Command "${this.command}" not found.`);
21
- }
22
- }
23
- }
@@ -1,25 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class InvalidOption extends BobError {
4
- option;
5
- optionsSignature;
6
- constructor(option, optionsSignature) {
7
- super(`Invalid option ${option} in not recognized`);
8
- this.option = option;
9
- this.optionsSignature = optionsSignature;
10
- }
11
- pretty() {
12
- const log = console.log;
13
- if (this.optionsSignature.length > 0) {
14
- log(chalk `\n{yellow Available options}:`);
15
- for (const option of this.optionsSignature) {
16
- const type = option.type ? chalk `{white (${option.type})}` : '';
17
- const nameWithAlias = `--${option.name}${option.alias?.map(a => `, -${a}`).join('') ?? ''}`;
18
- const spaces = ' '.repeat(30 - nameWithAlias.length);
19
- log(chalk ` {green ${nameWithAlias}} ${spaces} ${option.help ?? '\b'} ${type}`);
20
- }
21
- log('');
22
- }
23
- log(chalk ` {white.bgRed ERROR } Option {bold.yellow ${this.option}} is not recognized.`);
24
- }
25
- }
@@ -1,7 +0,0 @@
1
- import { BobError } from "../errors/BobError.js";
2
- import { ArgSignature } from "../CommandParser.js";
3
- export declare class MissingRequiredArgumentValue extends BobError {
4
- readonly paramSignature: ArgSignature;
5
- constructor(paramSignature: ArgSignature);
6
- pretty(): void;
7
- }
@@ -1,16 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class MissingRequiredArgumentValue extends BobError {
4
- paramSignature;
5
- constructor(paramSignature) {
6
- super(`Argument "${paramSignature.name}" is required.`);
7
- this.paramSignature = paramSignature;
8
- }
9
- pretty() {
10
- const log = console.log;
11
- if (this.paramSignature.help) {
12
- log(chalk `{yellow Help}: ${this.paramSignature.help}\n`);
13
- }
14
- log(chalk ` {white.bgRed ERROR } Argument {bold.yellow ${this.paramSignature.name}} is required.`);
15
- }
16
- }
@@ -1,8 +0,0 @@
1
- import { BobError } from "../errors/BobError.js";
2
- import { ArgSignature } from "../CommandParser.js";
3
- export declare class MissingSignatureArgument extends BobError {
4
- private argument;
5
- private argumentSignatures;
6
- constructor(argument: string, argumentSignatures: ArgSignature[]);
7
- pretty(): void;
8
- }
@@ -1,24 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class MissingSignatureArgument extends BobError {
4
- argument;
5
- argumentSignatures;
6
- constructor(argument, argumentSignatures) {
7
- super(`Missing ${argument} in the command signature`);
8
- this.argument = argument;
9
- this.argumentSignatures = argumentSignatures;
10
- }
11
- pretty() {
12
- const log = console.log;
13
- if (this.argumentSignatures.length) {
14
- log(chalk `\n{yellow Available arguments}:`);
15
- for (const argument of this.argumentSignatures) {
16
- const type = argument.type ? chalk `{white (${argument.type})}` : '';
17
- const spaces = ' '.repeat(20 - argument.name.length);
18
- log(chalk ` {green ${argument.name}} ${spaces} ${argument.help ?? '\b'} ${type}`);
19
- }
20
- log('');
21
- }
22
- log(chalk ` {white.bgRed ERROR } Argument {bold.yellow ${this.argument}} is missing in the signature.`);
23
- }
24
- }
@@ -1,8 +0,0 @@
1
- import { BobError } from "../errors/BobError.js";
2
- import { ArgSignature } from "../CommandParser.js";
3
- export declare class MissingSignatureOption extends BobError {
4
- private option;
5
- private optionsSignature;
6
- constructor(option: string, optionsSignature: ArgSignature[]);
7
- pretty(): void;
8
- }
@@ -1,24 +0,0 @@
1
- import chalk from "chalk";
2
- import { BobError } from "../errors/BobError.js";
3
- export class MissingSignatureOption extends BobError {
4
- option;
5
- optionsSignature;
6
- constructor(option, optionsSignature) {
7
- super(`Missing ${option} in the command signature`);
8
- this.option = option;
9
- this.optionsSignature = optionsSignature;
10
- }
11
- pretty() {
12
- const log = console.log;
13
- if (this.optionsSignature.length) {
14
- log(chalk `{yellow Available options}:`);
15
- for (const option of this.optionsSignature) {
16
- const type = option.type ? chalk `{white (${option.type})}` : '';
17
- const spaces = ' '.repeat(20 - option.name.length);
18
- log(chalk ` {green ${option.name}} ${spaces} ${option.help ?? '\b'} ${type}`);
19
- }
20
- log('');
21
- }
22
- log(chalk ` {white.bgRed ERROR } Option {bold.yellow ${this.option}} is missing in the signature.`);
23
- }
24
- }
@@ -1,3 +0,0 @@
1
- export * from './BobError.js';
2
- export * from './BadCommandParameter.js';
3
- export * from './BadCommandOption.js';
@@ -1,3 +0,0 @@
1
- export * from './BobError.js';
2
- export * from './BadCommandParameter.js';
3
- export * from './BadCommandOption.js';
@@ -1,5 +0,0 @@
1
- export * from './Command.js';
2
- export * from './Cli.js';
3
- export * from './errors/index.js';
4
- export * from './contracts/index.js';
5
- export * from './options/index.js';
@@ -1,5 +0,0 @@
1
- export * from './Command.js';
2
- export * from './Cli.js';
3
- export * from './errors/index.js';
4
- export * from './contracts/index.js';
5
- export * from './options/index.js';
@@ -1 +0,0 @@
1
- export declare function generateSpace(nb: number): string;
@@ -1,3 +0,0 @@
1
- export function generateSpace(nb) {
2
- return new Array(nb + 5).join(' ');
3
- }
@@ -1,9 +0,0 @@
1
- import { Command } from "../Command.js";
2
- import { CommandOption } from "../contracts/index.js";
3
- export declare class HelpOption implements CommandOption<Command> {
4
- option: string;
5
- alias: string[];
6
- defaultValue: boolean;
7
- description: string;
8
- handler(this: Command): Promise<number | void>;
9
- }
@@ -1,70 +0,0 @@
1
- import chalk from "chalk";
2
- import { generateSpace } from "../lib/string.js";
3
- export class HelpOption {
4
- option = 'help';
5
- alias = ['h'];
6
- defaultValue = false;
7
- description = chalk `Display help for the given command. When no command is given display help for the {green list} command`;
8
- async handler() {
9
- const log = console.log;
10
- const availableArguments = Object.values(this.parser.getArgumentSignatures());
11
- const availableOptions = Object.values(this.parser.getOptionSignatures())
12
- .map((signature) => ({
13
- ...signature,
14
- optionWithAlias: `--${signature.name}${signature.alias?.map(a => `, -${a}`).join('') ?? ''}`
15
- }));
16
- const requiredArguments = availableArguments.filter((signature) => !signature.optional);
17
- log(chalk `{yellow Description}:`);
18
- log(chalk ` ${this.description}\n`);
19
- log(chalk `{yellow Usage}:`);
20
- log(chalk ` ${this.command} ${requiredArguments.length > 0 ? requiredArguments.map((signature) => `<${signature.name}>`).join(' ') : '\b'} [options]`);
21
- const maxOptionLength = Math.max(...availableOptions.map((signature) => signature.optionWithAlias.length)) ?? 0;
22
- const maxArgumentLength = Math.max(...availableArguments.map((arg) => arg.name.length)) ?? 0;
23
- const maxLength = maxArgumentLength > maxOptionLength ? maxArgumentLength : maxOptionLength;
24
- if (availableArguments.length > 0) {
25
- log(chalk `\n{yellow Arguments}:`);
26
- for (const signature of availableArguments) {
27
- const spaces = generateSpace(maxLength - signature.name.length);
28
- let message = chalk ` {green ${signature.name}} ${spaces} ${signature.help ?? '\b'}`;
29
- if (signature.defaultValue !== undefined && signature.optional) {
30
- const defaultValue = signature.type === 'array' ? JSON.stringify(signature.defaultValue) : signature.defaultValue;
31
- message += chalk ` {yellow [default: ${defaultValue}]}`;
32
- }
33
- if (signature.variadic) {
34
- message += chalk ` {white (variadic)}`;
35
- }
36
- log(message);
37
- }
38
- }
39
- if (availableOptions.length > 0) {
40
- log(chalk `\n{yellow Options}:`);
41
- for (const signature of availableOptions) {
42
- const spaces = generateSpace(maxLength - signature.optionWithAlias.length);
43
- let message = chalk `{green ${signature.optionWithAlias}} ${spaces} ${signature.help ?? '\b'}`;
44
- if (signature.type) {
45
- message += chalk ` {white (${signature.type})}`;
46
- }
47
- if (signature.defaultValue !== undefined && signature.optional) {
48
- const defaultValue = signature.type === 'array' ? JSON.stringify(signature.defaultValue) : signature.defaultValue;
49
- message += chalk ` {yellow [default: ${defaultValue}]}`;
50
- }
51
- log(message);
52
- }
53
- }
54
- if (this.commandsExamples.length > 0) {
55
- log(chalk `\n{yellow Examples}:`);
56
- let binaryName = process.argv[0].split('/').pop();
57
- if (binaryName === 'node') {
58
- binaryName += ' ' + process.argv[1].split('/').pop();
59
- }
60
- for (const [index, example] of this.commandsExamples.entries()) {
61
- if (index > 0) {
62
- log('');
63
- }
64
- log(` ${example.description}\n`);
65
- log(chalk ` {green ${binaryName} ${example.command}}`);
66
- }
67
- }
68
- return -1;
69
- }
70
- }
@@ -1 +0,0 @@
1
- export * from './HelpOption.js';
@@ -1 +0,0 @@
1
- export * from './HelpOption.js';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes