test: should correctly parse the command options (#2688)
This commit is contained in:
parent
196bec0ede
commit
10e46b21f0
@ -40,4 +40,21 @@ describe('app command', () => {
|
||||
expect(app.cli.parseHandleByIPCServer(['node', 'cli', 'nocobase', 'subparent', 'testaa'])).toBeTruthy();
|
||||
expect(app.cli.parseHandleByIPCServer(['node', 'cli', 'nocobase', 'subparent', 'testbb'])).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should correctly parse the command multiple times with varying parameters', async () => {
|
||||
const fn = jest.fn();
|
||||
|
||||
app
|
||||
.command('test1')
|
||||
.option('-a, --aaa <aaa>', 'aaa option')
|
||||
.action((options) => {
|
||||
fn(options);
|
||||
});
|
||||
|
||||
await app.runCommand('test1', '-a', 'aaa');
|
||||
expect(fn).toBeCalledWith({ aaa: 'aaa' });
|
||||
|
||||
await app.runCommand('test1');
|
||||
expect(fn).toBeCalledWith({});
|
||||
});
|
||||
});
|
||||
|
@ -368,7 +368,6 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
.usage('[command] [options]')
|
||||
.hook('preAction', async (_, actionCommand) => {
|
||||
this._actionCommand = actionCommand;
|
||||
|
||||
this.activatedCommand = {
|
||||
name: getCommandFullName(actionCommand),
|
||||
};
|
||||
@ -416,6 +415,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
|
||||
return command;
|
||||
} catch (error) {
|
||||
console.log({ error });
|
||||
if (!this.activatedCommand) {
|
||||
this.activatedCommand = {
|
||||
name: 'unknown',
|
||||
@ -442,8 +442,8 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
_actionCommand.addOption(option);
|
||||
}
|
||||
}
|
||||
this.activatedCommand = null;
|
||||
this._actionCommand = null;
|
||||
this.activatedCommand = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user