alias support, test file (TODO proper tests)

This commit is contained in:
Erik 2023-02-12 16:30:54 +02:00
parent cdab7930cd
commit b1a7a27cfe
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
2 changed files with 25 additions and 2 deletions

View File

@ -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
View 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)