diff --git a/src/classes/Command.ts b/src/classes/Command.ts index 98b6354..88057e6 100644 --- a/src/classes/Command.ts +++ b/src/classes/Command.ts @@ -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[] { diff --git a/tests/Parser.test.js b/tests/Parser.test.js new file mode 100644 index 0000000..2653ed0 --- /dev/null +++ b/tests/Parser.test.js @@ -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) \ No newline at end of file