cli-forge 0.2.0 → 0.3.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/bin/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const mycli: import("../src").CLI<import("dist/packages/parser/src").ParsedArgs, import("dist/packages/parser/src").ParsedArgs>;
3
+ export default mycli;
package/bin/cli.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const src_1 = require("../src");
5
+ const generate_documentation_1 = require("./commands/generate-documentation");
6
+ const init_1 = require("./commands/init");
7
+ const mycli = (0, init_1.withInit)((0, generate_documentation_1.withGenerateDocumentation)((0, src_1.cli)('cli-forge')));
8
+ exports.default = mycli;
9
+ mycli.forge();
10
+ //# sourceMappingURL=cli.js.map
package/bin/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../packages/cli-forge/bin/cli.ts"],"names":[],"mappings":";;;AAEA,gCAA6B;AAC7B,8EAA8E;AAC9E,0CAA2C;AAE3C,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,IAAA,kDAAyB,EAAC,IAAA,SAAG,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAEpE,kBAAe,KAAK,CAAC;AAErB,KAAK,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { ParsedArgs } from '@cli-forge/parser';
2
+ import { CLI } from '../../src';
3
+ type GenerateDocsArgs = {
4
+ cli: string;
5
+ output: string;
6
+ format: string;
7
+ export: string;
8
+ };
9
+ export declare function withGenerateDocumentationArgs<T extends ParsedArgs>(cmd: CLI<T, T & GenerateDocsArgs>): CLI<T & {
10
+ cli: string;
11
+ } & {
12
+ output: string;
13
+ } & {
14
+ format: string;
15
+ } & {
16
+ export: string;
17
+ }, T & {
18
+ cli: string;
19
+ } & {
20
+ output: string;
21
+ } & {
22
+ format: string;
23
+ } & {
24
+ export: string;
25
+ }>;
26
+ export declare function withGenerateDocumentation<T extends ParsedArgs>(cli: CLI<T>): CLI<T, T>;
27
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withGenerateDocumentationArgs = withGenerateDocumentationArgs;
4
+ exports.withGenerateDocumentation = withGenerateDocumentation;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const src_1 = require("../../src");
8
+ const documentation_1 = require("../../src/lib/documentation");
9
+ const fs_1 = require("../utils/fs");
10
+ function withGenerateDocumentationArgs(cmd) {
11
+ return cmd
12
+ .positional('cli', {
13
+ type: 'string',
14
+ description: 'Path to the cli that docs should be generated for.',
15
+ required: true,
16
+ })
17
+ .option('output', {
18
+ alias: ['o'],
19
+ type: 'string',
20
+ description: 'Where should the documentation be output?',
21
+ default: 'docs',
22
+ })
23
+ .option('format', {
24
+ type: 'string',
25
+ description: 'What format should the documentation be output in? (json, md)',
26
+ default: 'md',
27
+ })
28
+ .option('export', {
29
+ type: 'string',
30
+ description: 'The name of the export that contains the CLI instance. By default, docs will be generated for the default export.',
31
+ });
32
+ }
33
+ function withGenerateDocumentation(cli) {
34
+ return cli.command('generate-documentation', {
35
+ description: 'Generate documentation for the given CLI',
36
+ builder: withGenerateDocumentationArgs,
37
+ handler: async (args) => {
38
+ if (args.cli.startsWith('./')) {
39
+ args.cli = (0, node_path_1.join)(process.cwd(), args.cli);
40
+ }
41
+ const cliModule = await Promise.resolve(`${args.cli}`).then(s => require(s));
42
+ const cli = cliModule[args.export || 'default'] ?? cliModule;
43
+ if (!(cli instanceof src_1.CLI)) {
44
+ throw new Error(`${args.cli}${args.export ? '#' + args.export : ''} is not a CLI.`);
45
+ }
46
+ const documentation = (0, documentation_1.generateDocumentation)(cli);
47
+ if (args.format === 'md') {
48
+ await generateMarkdownDocumentation(documentation, args);
49
+ }
50
+ else if (args.format === 'json') {
51
+ const outfile = args.output.endsWith('json')
52
+ ? args.output
53
+ : (0, node_path_1.join)(args.output, cli.name + '.json');
54
+ const outdir = (0, node_path_1.dirname)(outfile);
55
+ (0, fs_1.ensureDirSync)(outdir);
56
+ (0, node_fs_1.writeFileSync)(outfile, JSON.stringify(documentation, null, 2));
57
+ }
58
+ },
59
+ });
60
+ }
61
+ async function generateMarkdownDocumentation(docs, args) {
62
+ const md = await importMarkdownFactory();
63
+ await generateMarkdownForSingleCommand(docs, (0, node_path_1.join)(args.output, docs.name), md);
64
+ }
65
+ async function generateMarkdownForSingleCommand(docs, out, md) {
66
+ const subcommands = docs.subcommands;
67
+ const outdir = subcommands.length ? out : (0, node_path_1.dirname)(out);
68
+ const outname = subcommands.length ? 'index' : docs.name;
69
+ (0, fs_1.ensureDirSync)(outdir);
70
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(outdir, outname + '.md'), md.h1(docs.name, ...[
71
+ docs.description,
72
+ getPositionalArgsFragment(docs.positionals, md),
73
+ getFlagArgsFragment(docs.options, md),
74
+ getSubcommandsFragment(docs.subcommands, md),
75
+ ].filter(isTruthy)));
76
+ for (const subcommand of docs.subcommands) {
77
+ await generateMarkdownForSingleCommand(subcommand, (0, node_path_1.join)(outdir, subcommand.name), md);
78
+ }
79
+ }
80
+ function formatOption(option, md) {
81
+ return md.h3(option.key, ...[
82
+ md.bold('Type:') +
83
+ ' ' +
84
+ (option.type === 'array'
85
+ ? `${option.items}[]`
86
+ : option.type),
87
+ option.description,
88
+ option.default ? md.bold('Default:') + ' ' + option.default : undefined,
89
+ option.required ? md.bold('Required') : undefined,
90
+ option.alias?.length
91
+ ? md.h4('Aliases', md.ul(...option.alias))
92
+ : undefined,
93
+ ].filter(isTruthy));
94
+ }
95
+ function getPositionalArgsFragment(positionals, md) {
96
+ if (positionals?.length === 0) {
97
+ return undefined;
98
+ }
99
+ return md.h2('Positional Arguments', ...positionals.map((positional) => formatOption(positional, md)));
100
+ }
101
+ function getFlagArgsFragment(options, md) {
102
+ if (Object.keys(options).length === 0) {
103
+ return undefined;
104
+ }
105
+ return md.h2('Flags', ...Object.values(options).map((option) => formatOption(option, md)));
106
+ }
107
+ function getSubcommandsFragment(subcommands, md) {
108
+ if (subcommands.length === 0) {
109
+ return undefined;
110
+ }
111
+ return md.h2('Subcommands', ...subcommands.map((subcommand) => md.link(`./${subcommand.name}`, subcommand.name)));
112
+ }
113
+ function isTruthy(value) {
114
+ return !!value;
115
+ }
116
+ async function importMarkdownFactory() {
117
+ try {
118
+ return await Promise.resolve().then(() => require('markdown-factory'));
119
+ }
120
+ catch {
121
+ throw new Error('Could not find markdown-factory. Please install it to generate markdown documentation.');
122
+ }
123
+ }
124
+ //# sourceMappingURL=generate-documentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-documentation.js","sourceRoot":"","sources":["../../../../../packages/cli-forge/bin/commands/generate-documentation.ts"],"names":[],"mappings":";;AAqBA,sEA0BC;AAED,8DA4BC;AA3ED,qCAAwC;AACxC,yCAA0C;AAE1C,mCAAgC;AAChC,+DAGqC;AACrC,oCAA4C;AAW5C,SAAgB,6BAA6B,CAC3C,GAAiC;IAEjC,OAAO,GAAG;SACP,UAAU,CAAC,KAAK,EAAE;QACjB,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,oDAAoD;QACjE,QAAQ,EAAE,IAAI;KACf,CAAC;SACD,MAAM,CAAC,QAAQ,EAAE;QAChB,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,2CAA2C;QACxD,OAAO,EAAE,MAAM;KAChB,CAAC;SACD,MAAM,CAAC,QAAQ,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,+DAA+D;QACjE,OAAO,EAAE,IAAI;KACd,CAAC;SACD,MAAM,CAAC,QAAQ,EAAE;QAChB,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,mHAAmH;KACtH,C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Args = {
4
+ cliName: string;
5
+ output: string;
6
+ format: string;
7
+ };
8
+ export declare function withInitArgs<T extends ParsedArgs>(cmd: CLI<T, T & InitArgs>): CLI<T & {
9
+ cliName: string;
10
+ } & {
11
+ output: string;
12
+ } & {
13
+ format: string;
14
+ }, T & {
15
+ cliName: string;
16
+ } & {
17
+ output: string;
18
+ } & {
19
+ format: string;
20
+ }>;
21
+ export declare function withInit<T extends ParsedArgs>(cli: CLI<T>): CLI<T, T>;
22
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withInitArgs = withInitArgs;
4
+ exports.withInit = withInit;
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const fs_1 = require("../utils/fs");
8
+ const package_json_1 = require("../../package.json");
9
+ const node_child_process_1 = require("node:child_process");
10
+ function withInitArgs(cmd) {
11
+ return cmd
12
+ .positional('cliName', {
13
+ type: 'string',
14
+ description: 'Name of the CLI to generate.',
15
+ required: true,
16
+ })
17
+ .option('output', {
18
+ alias: ['o'],
19
+ type: 'string',
20
+ description: 'Where should the CLI be created?',
21
+ })
22
+ .option('format', {
23
+ type: 'string',
24
+ default: 'ts',
25
+ description: 'What format should the CLI be in? (js, ts)',
26
+ });
27
+ }
28
+ function withInit(cli) {
29
+ return cli.command('init', {
30
+ description: 'Generate a new CLI',
31
+ builder: withInitArgs,
32
+ handler: async (args) => {
33
+ args.output ??= process.cwd();
34
+ (0, fs_1.ensureDirSync)(args.output);
35
+ const packageJsonPath = (0, node_path_1.join)(args.output, 'package.json');
36
+ const cliPath = (0, node_path_1.join)(args.output, 'bin', `${args.cliName}.${args.format}`);
37
+ const packageJsonContent = readJsonOr(packageJsonPath, { name: args.cliName });
38
+ packageJsonContent.bin ??= {};
39
+ packageJsonContent.bin[args.cliName] = (0, node_path_1.relative)(args.output, cliPath);
40
+ packageJsonContent.dependencies ??= {};
41
+ packageJsonContent.dependencies['cli-forge'] ??= package_json_1.version;
42
+ (0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJsonContent, null, 2));
43
+ (0, fs_1.ensureDirSync)((0, node_path_1.dirname)(cliPath));
44
+ (0, node_fs_1.writeFileSync)(cliPath, args.format === 'ts'
45
+ ? TS_CLI_CONTENTS(args.cliName)
46
+ : JS_CLI_CONTENTS(args.cliName));
47
+ const installCommand = (0, node_fs_1.existsSync)((0, node_path_1.join)(args.output, 'yarn.lock'))
48
+ ? 'yarn'
49
+ : (0, node_fs_1.existsSync)((0, node_path_1.join)(args.output, 'pnpm-lock.yaml'))
50
+ ? 'pnpm'
51
+ : (0, node_fs_1.existsSync)((0, node_path_1.join)(args.output, 'bun.lockb'))
52
+ ? 'bun'
53
+ : 'npm';
54
+ (0, node_child_process_1.execSync)(`${installCommand} install`);
55
+ },
56
+ });
57
+ }
58
+ const COMMON_CONTENTS = (name) => `const myCLI = cli('${name}')
59
+ .command('hello', {
60
+ builder: (args) => args.positional('name', {type: 'string'}),
61
+ handler: (args) => {
62
+ console.log('hello', args.name);
63
+ }
64
+ })`;
65
+ const JS_CLI_CONTENTS = (name) => `const { cli } = require('cli-forge');
66
+
67
+ ${COMMON_CONTENTS(name)}
68
+
69
+ module.exports = myCLI;
70
+
71
+ if (require.main === module) {
72
+ myCLI.forge();
73
+ }
74
+ `;
75
+ const TS_CLI_CONTENTS = (name) => `import { cli } from 'cli-forge';
76
+
77
+ ${COMMON_CONTENTS(name)}
78
+
79
+ export default myCLI;
80
+
81
+ if (require.main === module) {
82
+ myCLI.forge();
83
+ }
84
+ `;
85
+ function readJsonOr(filePath, alt) {
86
+ try {
87
+ const contents = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
88
+ return JSON.parse(contents);
89
+ }
90
+ catch {
91
+ return alt;
92
+ }
93
+ }
94
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../../packages/cli-forge/bin/commands/init.ts"],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AAE,EAAE,CAAC;;EAExC,eAAe,CAAC,IAAI,CAAC;;;;;;;CAOtB,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC;;EAExC,eAAe,CAAC,IAAI,CAAC;;;;;;;CAOtB,CAAC;AAEF,SAAS,UAAU,CAAI,QAAgB,EAAE,GAAM;IAC7C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAA,sBAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function ensureDirSync(dir: string): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureDirSync = ensureDirSync;
4
+ const node_fs_1 = require("node:fs");
5
+ function ensureDirSync(dir) {
6
+ try {
7
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true });
8
+ }
9
+ catch (e) {
10
+ if (!(0, node_fs_1.existsSync)(dir)) {
11
+ throw new Error(`Could not create directory: ${dir}`, { cause: e });
12
+ }
13
+ }
14
+ }
15
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../../../packages/cli-forge/bin/utils/fs.ts"],"names":[],"mappings":";;AAEA,sCAQC;AAVD,qCAAgD;AAEhD,SAAgB,aAAa,CAAC,GAAW;IACvC,IAAI,CAAC;QACH,IAAA,mBAAS,EAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,IAAA,oBAAU,EAAC,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "cli-forge",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
- "@cli-forge/parser": "0.2.0"
6
+ "@cli-forge/parser": "0.3.0"
7
+ },
8
+ "peerDependencies": {
9
+ "markdown-factory": "0.2.0"
10
+ },
11
+ "peerDependenciesMeta": {
12
+ "markdown-factory": {
13
+ "optional": true
14
+ }
7
15
  },
8
16
  "type": "commonjs",
9
17
  "main": "./src/index.js",
@@ -14,6 +22,9 @@
14
22
  "directory": "packages/cli-forge",
15
23
  "url": "https://github.com/AgentEnder/cli-forge"
16
24
  },
25
+ "bin": {
26
+ "cli-forge": "./bin/cli.js"
27
+ },
17
28
  "publishConfig": {
18
29
  "access": "public"
19
30
  },
package/src/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './lib/cli-forge';
2
+ export { default } from './lib/cli-forge';
package/src/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  tslib_1.__exportStar(require("./lib/cli-forge"), exports);
6
+ var cli_forge_1 = require("./lib/cli-forge");
7
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return cli_forge_1.default; } });
5
8
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/cli-forge/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/cli-forge/src/index.ts"],"names":[],"mappings":";;;;AAAA,0DAAgC;AAChC,6CAA0C;AAAjC,oGAAA,OAAO,OAAA"}
@@ -4,6 +4,11 @@ export type CLICommandOptions<TInitial extends ParsedArgs, TArgs extends TInitia
4
4
  builder?: (parser: CLI<TInitial>) => CLI<TArgs>;
5
5
  handler: (args: TArgs) => void | Promise<void>;
6
6
  };
7
+ export type ArgsOf<T extends CLI> = T extends {
8
+ configuration: {
9
+ handler: (args: infer TArgs) => void;
10
+ };
11
+ } ? TArgs : never;
7
12
  /**
8
13
  * The base class for a CLI application. This class is used to define the structure of the CLI.
9
14
  *
@@ -23,9 +28,9 @@ export type CLICommandOptions<TInitial extends ParsedArgs, TArgs extends TInitia
23
28
  * }).forge();
24
29
  * ```
25
30
  */
26
- export declare class CLI<T extends ParsedArgs = ParsedArgs> {
31
+ export declare class CLI<T extends ParsedArgs = ParsedArgs, T2 extends T = T> {
27
32
  name: string;
28
- protected configuration?: CLICommandOptions<T, T> | undefined;
33
+ configuration?: CLICommandOptions<T, T2> | undefined;
29
34
  private commands;
30
35
  private commandChain;
31
36
  private requiresCommand;
@@ -34,7 +39,7 @@ export declare class CLI<T extends ParsedArgs = ParsedArgs> {
34
39
  * @param name What should the name of the cli command be?
35
40
  * @param configuration Configuration for the current CLI command.
36
41
  */
37
- constructor(name: string, configuration?: CLICommandOptions<T, T> | undefined);
42
+ constructor(name: string, configuration?: CLICommandOptions<T, T2> | undefined);
38
43
  /**
39
44
  * Registers a new command with the CLI.
40
45
  * @param key What should the new command be called?
@@ -63,7 +68,7 @@ export declare class CLI<T extends ParsedArgs = ParsedArgs> {
63
68
  * @param config Configuration for the positional argument. See {@link OptionConfig}.
64
69
  * @returns Updated CLI instance with the new positional argument registered.
65
70
  */
66
- positional<TOption extends string, TOptionConfig extends OptionConfig>(name: TOption, config: TOptionConfig): CLI<T & { [key in TOption]: {
71
+ positional<TOption extends string, TOptionConfig extends OptionConfig>(name: TOption, config: TOptionConfig): CLI<T & { [key in TOption]: TOptionConfig["coerce"] extends (value: string) => infer TCoerce ? TCoerce : {
67
72
  string: string;
68
73
  number: number;
69
74
  boolean: boolean;
@@ -96,11 +101,16 @@ export declare class CLI<T extends ParsedArgs = ParsedArgs> {
96
101
  * @returns Promise that resolves when the handler completes.
97
102
  */
98
103
  forge(args?: string[]): Promise<void>;
104
+ getParser(): import("@cli-forge/parser").ReadonlyArgvParser<T & {
105
+ help: boolean;
106
+ }>;
107
+ getSubcommands(): Readonly<Record<string, CLI>>;
108
+ clone(): CLI<T, T2>;
99
109
  }
100
110
  /**
101
111
  * Constructs a CLI instance. See {@link CLI} for more information.
102
112
  * @param name Name for the top level CLI
103
113
  * @returns
104
114
  */
105
- export declare function cli(name: string): CLI<ParsedArgs>;
115
+ export declare function cli(name: string): CLI<ParsedArgs, ParsedArgs>;
106
116
  export default cli;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CLI = void 0;
4
4
  exports.cli = cli;
5
- const tslib_1 = require("tslib");
6
5
  const parser_1 = require("@cli-forge/parser");
7
6
  /**
8
7
  * The base class for a CLI application. This class is used to define the structure of the CLI.
@@ -24,6 +23,31 @@ const parser_1 = require("@cli-forge/parser");
24
23
  * ```
25
24
  */
26
25
  class CLI {
26
+ name;
27
+ configuration;
28
+ commands = {};
29
+ commandChain = [];
30
+ requiresCommand = false;
31
+ parser = new parser_1.ArgvParser({
32
+ unmatchedParser: (arg) => {
33
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
34
+ let currentCommand = this;
35
+ for (const command of this.commandChain) {
36
+ currentCommand = currentCommand.commands[command];
37
+ }
38
+ const command = currentCommand.commands[arg];
39
+ if (command && command.configuration) {
40
+ command.configuration.builder?.(command);
41
+ this.commandChain.push(arg);
42
+ return true;
43
+ }
44
+ return false;
45
+ },
46
+ }).option('help', {
47
+ type: 'boolean',
48
+ alias: ['h'],
49
+ description: 'Show help for the current command',
50
+ });
27
51
  /**
28
52
  * @param name What should the name of the cli command be?
29
53
  * @param configuration Configuration for the current CLI command.
@@ -31,31 +55,6 @@ class CLI {
31
55
  constructor(name, configuration) {
32
56
  this.name = name;
33
57
  this.configuration = configuration;
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- this.commands = {};
36
- this.commandChain = [];
37
- this.requiresCommand = false;
38
- this.parser = new parser_1.ArgvParser({
39
- unmatchedParser: (arg) => {
40
- var _a, _b;
41
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
42
- let currentCommand = this;
43
- for (const command of this.commandChain) {
44
- currentCommand = currentCommand.commands[command];
45
- }
46
- const command = currentCommand.commands[arg];
47
- if (command && command.configuration) {
48
- (_b = (_a = command.configuration).builder) === null || _b === void 0 ? void 0 : _b.call(_a, command);
49
- this.commandChain.push(arg);
50
- return true;
51
- }
52
- return false;
53
- },
54
- }).option('help', {
55
- type: 'boolean',
56
- alias: ['-h'],
57
- description: 'Show help for the current command',
58
- });
59
58
  }
60
59
  /**
61
60
  * Registers a new command with the CLI.
@@ -65,11 +64,12 @@ class CLI {
65
64
  */
66
65
  command(key, options) {
67
66
  if (key === '$0') {
68
- this.configuration = Object.assign(Object.assign({}, this.configuration), {
69
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- builder: options.builder,
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- handler: options.handler, description: options.description });
67
+ this.configuration = {
68
+ ...this.configuration,
69
+ builder: options.builder,
70
+ handler: options.handler,
71
+ description: options.description,
72
+ };
73
73
  }
74
74
  this.commands[key] = new CLI(key, options);
75
75
  this.commands[key].parser = this.parser;
@@ -85,7 +85,6 @@ class CLI {
85
85
  */
86
86
  option(name, config) {
87
87
  this.parser.option(name, config);
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
88
  return this;
90
89
  }
91
90
  /**
@@ -96,8 +95,7 @@ class CLI {
96
95
  * @returns Updated CLI instance with the new positional argument registered.
97
96
  */
98
97
  positional(name, config) {
99
- this.parser.option(name, config);
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ this.parser.positional(name, config);
101
99
  return this;
102
100
  }
103
101
  /**
@@ -114,15 +112,18 @@ class CLI {
114
112
  * @returns Help text for the current command.
115
113
  */
116
114
  formatHelp() {
117
- var _a, _b;
118
115
  const help = [];
119
116
  // eslint-disable-next-line @typescript-eslint/no-this-alias
120
117
  let command = this;
121
118
  for (const key of this.commandChain) {
122
119
  command = command.commands[key];
123
120
  }
124
- help.push(`Usage: ${[this.name, ...this.commandChain].join(' ')}`);
125
- if ((_a = command.configuration) === null || _a === void 0 ? void 0 : _a.description) {
121
+ help.push(`Usage: ${[
122
+ this.name,
123
+ ...this.commandChain,
124
+ ...command.parser.configuredPositionals.map((p) => `[${p.key}]`),
125
+ ].join(' ')}`);
126
+ if (command.configuration?.description) {
126
127
  help.push(command.configuration.description);
127
128
  }
128
129
  if (Object.keys(command.commands).length > 0) {
@@ -131,7 +132,7 @@ class CLI {
131
132
  }
132
133
  for (const key in command.commands) {
133
134
  const subcommand = command.commands[key];
134
- help.push(` ${key}${((_b = subcommand.configuration) === null || _b === void 0 ? void 0 : _b.description)
135
+ help.push(` ${key}${subcommand.configuration?.description
135
136
  ? ' - ' + subcommand.configuration.description
136
137
  : ''}`);
137
138
  }
@@ -140,7 +141,6 @@ class CLI {
140
141
  help.push('Options:');
141
142
  }
142
143
  for (const key in this.parser.configuredOptions) {
143
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
144
  const option = this.parser.configuredOptions[key];
145
145
  help.push(` --${key}${option.description ? ' - ' + option.description : ''}`);
146
146
  }
@@ -161,52 +161,61 @@ class CLI {
161
161
  * @param cmd The command to run.
162
162
  * @param args The arguments to pass to the command.
163
163
  */
164
- runCommand(cmd, args) {
165
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
166
- var _a;
167
- try {
168
- if (cmd.requiresCommand) {
169
- throw new Error(`${[this.name, ...this.commandChain].join(' ')} requires a command`);
170
- }
171
- if ((_a = cmd.configuration) === null || _a === void 0 ? void 0 : _a.handler) {
172
- yield cmd.configuration.handler(args);
173
- }
174
- else {
175
- throw new Error(`${[this.name, ...this.commandChain].join(' ')} is not implemented.`);
176
- }
164
+ async runCommand(cmd, args) {
165
+ try {
166
+ if (cmd.requiresCommand) {
167
+ throw new Error(`${[this.name, ...this.commandChain].join(' ')} requires a command`);
168
+ }
169
+ if (cmd.configuration?.handler) {
170
+ await cmd.configuration.handler(args);
177
171
  }
178
- catch (_b) {
179
- process.exitCode = 1;
180
- this.printHelp();
172
+ else {
173
+ throw new Error(`${[this.name, ...this.commandChain].join(' ')} is not implemented.`);
181
174
  }
182
- });
175
+ }
176
+ catch (e) {
177
+ process.exitCode = 1;
178
+ console.error(e);
179
+ this.printHelp();
180
+ }
183
181
  }
184
182
  /**
185
183
  * Parses argv and executes the CLI
186
184
  * @param args argv. Defaults to process.argv.slice(2)
187
185
  * @returns Promise that resolves when the handler completes.
188
186
  */
189
- forge() {
190
- return tslib_1.__awaiter(this, arguments, void 0, function* (args = process.argv.slice(2)) {
191
- var _a, _b, _c;
192
- // Parsing the args does two things:
193
- // - builds argv to pass to handler
194
- // - fills the command chain + registers commands
195
- const argv = this.parser.parse(args);
196
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
197
- let currentCommand = this;
198
- for (const command of this.commandChain) {
199
- currentCommand = currentCommand.commands[command];
200
- }
201
- if (argv.help) {
202
- this.printHelp();
203
- return;
204
- }
205
- const finalArgV = currentCommand === this
206
- ? ((_c = (_b = (_a = this.configuration) === null || _a === void 0 ? void 0 : _a.builder) === null || _b === void 0 ? void 0 : _b.call(_a, this).parser) !== null && _c !== void 0 ? _c : this.parser).parse(args)
207
- : argv;
208
- yield this.runCommand(currentCommand, finalArgV);
209
- });
187
+ async forge(args = process.argv.slice(2)) {
188
+ // Parsing the args does two things:
189
+ // - builds argv to pass to handler
190
+ // - fills the command chain + registers commands
191
+ const argv = this.parser.parse(args);
192
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
193
+ let currentCommand = this;
194
+ for (const command of this.commandChain) {
195
+ currentCommand = currentCommand.commands[command];
196
+ }
197
+ if (argv.help) {
198
+ this.printHelp();
199
+ return;
200
+ }
201
+ const finalArgV = currentCommand === this
202
+ ? (this.configuration?.builder?.(this).parser ?? this.parser).parse(args)
203
+ : argv;
204
+ await this.runCommand(currentCommand, finalArgV);
205
+ }
206
+ getParser() {
207
+ return this.parser.asReadonly();
208
+ }
209
+ getSubcommands() {
210
+ return this.commands;
211
+ }
212
+ clone() {
213
+ const clone = new CLI(this.name, this.configuration);
214
+ clone.commands = { ...this.commands };
215
+ clone.commandChain = [...this.commandChain];
216
+ clone.requiresCommand = this.requiresCommand;
217
+ clone.parser = this.parser.clone();
218
+ return clone;
210
219
  }
211
220
  }
212
221
  exports.CLI = CLI;
@@ -1 +1 @@
1
- {"version":3,"file":"cli-forge.js","sourceRoot":"","sources":["../../../../../packages/cli-forge/src/lib/cli-forge.ts"],"names":[],"mappings":";;;AAgSA,kBAEC;;AAlSD,8CAK2B;AAW3B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,GAAG;IA0Bd;;;OAGG;IACH,YACS,IAAY,EACT,aAAuC;QAD1C,SAAI,GAAJ,IAAI,CAAQ;QACT,kBAAa,GAAb,aAAa,CAA0B;QA/BnD,8DAA8D;QACtD,aAAQ,GAA6B,EAAE,CAAC;QACxC,iBAAY,GAAa,EAAE,CAAC;QAC5B,oBAAe,GAAG,KAAK,CAAC;QACxB,WAAM,GAAG,IAAI,mBAAU,CAAI;YACjC,eAAe,EAAE,CAAC,GAAG,EAAE,EAAE;;gBACvB,gGAAgG;gBAChG,IAAI,cAAc,GAAa,IAAI,CAAC;gBACpC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;oBACxC,cAAc,GAAG,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBACpD,CAAC;gBACD,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC7C,IAAI,OAAO,IAAI,OAAO,CAAC,aAA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,CAAC,QAAyC,CAAC;IACxD,CAAC;IAED,KAAK;QACH,MAAM,KAAK,GAAG,IAAI,GAAG,CAAQ,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5D,KAAK,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACtC,KAAK,CAAC,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAC5C,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC7C,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAS,CAAC;QAC1C,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5QD,kBA4QC;AAED;;;;GAIG;AACH,SAAgB,GAAG,CAAC,IAAY;IAC9B,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;AACvB,CAAC;AAED,kBAAe,GAAG,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { OptionConfig } from '@cli-forge/parser';
2
+ import { CLI } from './cli-forge';
3
+ export type Documentation = {
4
+ name: string;
5
+ description?: string;
6
+ options: Readonly<Record<string, OptionConfig & {
7
+ key: string;
8
+ }>>;
9
+ positionals: readonly Readonly<OptionConfig & {
10
+ key: string;
11
+ }>[];
12
+ subcommands: Documentation[];
13
+ };
14
+ export declare function generateDocumentation(cli: CLI): {
15
+ name: string;
16
+ description: string | undefined;
17
+ options: Readonly<{
18
+ unmatched: OptionConfig<any> & {
19
+ key: string;
20
+ position?: number;
21
+ };
22
+ '--'?: (OptionConfig<any> & {
23
+ key: string;
24
+ position?: number;
25
+ }) | undefined;
26
+ help: OptionConfig<any> & {
27
+ key: string;
28
+ position?: number;
29
+ };
30
+ }>;
31
+ positionals: readonly Readonly<OptionConfig<any> & {
32
+ key: string;
33
+ position?: number;
34
+ }>[];
35
+ subcommands: Documentation[];
36
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateDocumentation = generateDocumentation;
4
+ function generateDocumentation(cli) {
5
+ // Ensure current command's options are built.
6
+ if (cli.configuration?.builder) {
7
+ cli.configuration.builder(cli);
8
+ }
9
+ const parser = cli.getParser();
10
+ const options = parser.configuredOptions;
11
+ const positionals = parser.configuredPositionals;
12
+ const subcommands = Object.values(cli.getSubcommands()).map((cmd) => generateDocumentation(cmd.clone()));
13
+ return {
14
+ name: cli.name,
15
+ description: cli.configuration?.description,
16
+ options,
17
+ positionals,
18
+ subcommands,
19
+ };
20
+ }
21
+ //# sourceMappingURL=documentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentation.js","sourceRoot":"","sources":["../../../../../packages/cli-forge/src/lib/documentation.ts"],"names":[],"mappings":";;AAWA,sDAoBC;AApBD,SAAgB,qBAAqB,CAAC,GAAQ;IAC5C,8CAA8C;IAC9C,IAAI,GAAG,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC;QAC/B,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,EAAE,CAAC;IAE/B,MAAM,OAAO,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACzC,MAAM,WAAW,GAAG,MAAM,CAAC,qBAAqB,CAAC;IACjD,MAAM,WAAW,GAAoB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC,GAAG,CAC1E,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAC5C,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,WAAW,EAAE,GAAG,CAAC,aAAa,EAAE,WAAW;QAC3C,OAAO;QACP,WAAW;QACX,WAAW;KACZ,CAAC;AACJ,CAAC"}