md-hopper 1.0.0-alpha.3 → 1.0.0-alpha.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.
@@ -14,5 +14,5 @@ export declare class CommandClass<T extends DefaultOptions> {
14
14
  description(description: string): CommandClass<T>;
15
15
  option(...args: any[]): CommandClass<T>;
16
16
  requiredOption(...args: any[]): CommandClass<T>;
17
- action(action: Action): void;
17
+ action(command: string, action: Action): void;
18
18
  }
@@ -42,8 +42,11 @@ export class CommandClass {
42
42
  this.program = this.program.requiredOption(flags, ...args);
43
43
  return this;
44
44
  }
45
- action(action) {
45
+ action(command, action) {
46
46
  this.program = this.program.action(async (...args) => {
47
+ if (['help'].includes(command)) {
48
+ return action(this.args, ...args);
49
+ }
47
50
  const options = args[0];
48
51
  await this.init(options, getSettings(options.input || ''));
49
52
  for (const before of this.befores) {
@@ -1,5 +1,6 @@
1
1
  import { CommandClass } from '../../../_internal/utils/command.js';
2
2
  import { action } from './action.js';
3
+ const BASE_COMMAND = 'generate';
3
4
  const setAliases = (commandClass) => {
4
5
  commandClass
5
6
  .description('This command is used to exec target file.')
@@ -10,11 +11,11 @@ const setAliases = (commandClass) => {
10
11
  .option('-o, --output <filename>', 'output filename. default: README.md (replace)')
11
12
  .option('-i, --input <filename>', 'target root filename, default: README.md')
12
13
  .option('-D, --depth <filename>', 'depth level more than 0')
13
- .action(options => {
14
+ .action(BASE_COMMAND, options => {
14
15
  return action(options);
15
16
  });
16
17
  };
17
- const commands = ['generate', 'g'];
18
+ const commands = [BASE_COMMAND, 'g'];
18
19
  export const init = (program) => {
19
20
  for (const command of commands) {
20
21
  setAliases(new CommandClass(program).command(command));
@@ -1,11 +1,12 @@
1
1
  import { CommandClass } from '../../../_internal/utils/command.js';
2
2
  import { action } from './action.js';
3
+ const BASE_COMMAND = 'help';
3
4
  const setAliases = (commandClass) => {
4
- commandClass.description('This command is used to show help').action(options => {
5
+ commandClass.description('This command is used to show help').action(BASE_COMMAND, options => {
5
6
  return action(options);
6
7
  });
7
8
  };
8
- const commands = ['help', 'h'];
9
+ const commands = [BASE_COMMAND, 'h'];
9
10
  export const init = (program) => {
10
11
  for (const command of commands) {
11
12
  setAliases(new CommandClass(program).command(command));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md-hopper",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {