alias support, test file (TODO proper tests)
This commit is contained in:
parent
cdab7930cd
commit
b1a7a27cfe
@ -39,12 +39,12 @@ abstract class Command implements ICommand {
|
||||
|
||||
subcommand(name: string): SubcommandOption | null {
|
||||
name = name.toLowerCase();
|
||||
return this.subcommands.find((cmd) => cmd.name === name) || null;
|
||||
return this.subcommands.find((cmd) => cmd.name === name || cmd.aliases.includes(name)) || null;
|
||||
}
|
||||
|
||||
subcommandGroup(name: string): SubcommandGroupOption | null {
|
||||
name = name.toLowerCase();
|
||||
return this.subcommandGroups.find((opt) => opt.name === name) || null;
|
||||
return this.subcommandGroups.find((grp) => grp.name === name || grp.aliases.includes(name)) || null;
|
||||
}
|
||||
|
||||
private _subcommands(options: CommandOption[]): SubcommandOption[] {
|
||||
|
23
tests/Parser.test.js
Normal file
23
tests/Parser.test.js
Normal file
@ -0,0 +1,23 @@
|
||||
const { inspect } = require('node:util');
|
||||
const { Parser, Command, OptionType } = require('../build');
|
||||
|
||||
const command = new Command({name: 'create', options:[{name: 'registration-code', aliases: ['code'], type: OptionType.SUB_COMMAND}]})
|
||||
|
||||
const parser = new Parser({commands: [command], prefix: ''})
|
||||
const debug = (a) => console.log(inspect(a));
|
||||
|
||||
const handle = async (data) => {
|
||||
const raw = data.toString('utf-8');
|
||||
let words = raw.split(' ').map(word => word.trim());
|
||||
|
||||
words = words.filter(word => word.length);
|
||||
if (!words.length)
|
||||
return;
|
||||
debug((words));
|
||||
|
||||
const result = await parser.parseMessage(words.join(' '));
|
||||
debug(result)
|
||||
|
||||
}
|
||||
|
||||
process.stdin.on('data', handle)
|
Loading…
Reference in New Issue
Block a user