Skip to content

Commit 659a00a

Browse files
committed
test: test default sub commands
1 parent fadb70d commit 659a00a

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CommandRunner, SubCommand } from 'nest-commander';
2+
3+
import { LogService } from '../../common/log.service';
4+
5+
@SubCommand({ name: 'bottom', options: { isDefault: true } })
6+
export class BottomCommand extends CommandRunner {
7+
constructor(private readonly log: LogService) {
8+
super();
9+
}
10+
11+
async run() {
12+
this.log.log('top mid-1 bottom command');
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CommandRunner, SubCommand } from 'nest-commander';
2+
3+
import { LogService } from '../../common/log.service';
4+
import { BottomCommand } from './bottom.command';
5+
6+
@SubCommand({ name: 'mid-1', subCommands: [BottomCommand], options: { isDefault: true } })
7+
export class Mid1Command extends CommandRunner {
8+
constructor(private readonly log: LogService) {
9+
super();
10+
}
11+
12+
async run() {
13+
this.log.log('top mid-1 command');
14+
}
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { CommandRunner, SubCommand } from 'nest-commander';
2+
3+
import { LogService } from '../../common/log.service';
4+
5+
@SubCommand({ name: 'mid-2', aliases: ['m'] })
6+
export class Mid2Command extends CommandRunner {
7+
constructor(private readonly log: LogService) {
8+
super();
9+
}
10+
11+
async run() {
12+
this.log.log('top mid-2 command');
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Module } from '@nestjs/common';
2+
3+
import { LogService } from '../../common/log.service';
4+
import { BottomCommand } from './bottom.command';
5+
import { Mid1Command } from './mid-1.command';
6+
import { Mid2Command } from './mid-2.command';
7+
import { TopCommand } from './top.command';
8+
9+
@Module({
10+
providers: [LogService, TopCommand, Mid1Command, Mid2Command, BottomCommand],
11+
})
12+
export class NestedModule {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Command, CommandRunner } from 'nest-commander';
2+
3+
import { LogService } from '../../common/log.service';
4+
import { Mid1Command } from './mid-1.command';
5+
import { Mid2Command } from './mid-2.command';
6+
7+
@Command({ name: 'top', arguments: '[name]', subCommands: [Mid1Command, Mid2Command] })
8+
export class TopCommand extends CommandRunner {
9+
constructor(private readonly log: LogService) {
10+
super();
11+
}
12+
13+
async run(inputs: string[]) {
14+
this.log.log('top command');
15+
this.log.log(inputs);
16+
}
17+
}

integration/index.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
StringCommandSuite,
66
UnknownCommandSuite,
77
} from './basic/test/basic.command.spec';
8+
import { DefaultSubCommandSuite } from './default-sub-commands/test/default-sub-commands.spec';
89
import { DotCommandSuite } from './dot-command/test/dot.command.spec';
910
import { HelpSuite } from './help-tests/test/help.spec';
1011
import { MultipleCommandSuite } from './multiple/test/multiple.command.spec';
@@ -33,3 +34,4 @@ SetQuestionSuite.run();
3334
OptionChoiceSuite.run();
3435
DotCommandSuite.run();
3536
RegisterWithSubCommandsSuite.run();
37+
DefaultSubCommandSuite.run();

0 commit comments

Comments
 (0)