1
0
Fork 0

Last attempt

refactor/models
Bsian 2019-11-01 00:20:55 +00:00
parent 5076b7deef
commit bb81cf6842
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
2 changed files with 6 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import { Collection } from '.';
export default class Command { export default class Command {
name: string name: string
parentName: string
description?: string description?: string
usage?: string usage?: string

View File

@ -55,7 +55,7 @@ export default class Util {
} }
if (!resolvedCommand) return Promise.resolve({ cmd: null, args }); if (!resolvedCommand) return Promise.resolve({ cmd: null, args });
let label = `${command}`; let parentLabel = `${command}`;
let hasSubCommands = true; let hasSubCommands = true;
while (hasSubCommands) { while (hasSubCommands) {
if (!resolvedCommand.subcommands.size) { if (!resolvedCommand.subcommands.size) {
@ -64,11 +64,11 @@ export default class Util {
hasSubCommands = false; break; hasSubCommands = false; break;
} else if (resolvedCommand.subcommands.has(args[0])) { } else if (resolvedCommand.subcommands.has(args[0])) {
resolvedCommand = resolvedCommand.subcommands.get(args[0]); resolvedCommand = resolvedCommand.subcommands.get(args[0]);
args.shift(); label += ` ${args[0]}`; args.shift(); parentLabel += ` ${args[0]}`;
} else { } else {
for (const subCmd of resolvedCommand.subcommands.toArray()) { for (const subCmd of resolvedCommand.subcommands.toArray()) {
if (subCmd.aliases.includes(args[0])) { if (subCmd.aliases.includes(args[0])) {
resolvedCommand = subCmd; args.shift(); label += ` ${args[0]}`; break; resolvedCommand = subCmd; args.shift(); parentLabel += ` ${args[0]}`; break;
} else { } else {
hasSubCommands = false; break; hasSubCommands = false; break;
} }
@ -76,7 +76,7 @@ export default class Util {
} }
} }
const finalCommand = resolvedCommand; const finalCommand = resolvedCommand;
finalCommand.name = label; finalCommand.parentName = parentLabel;
return Promise.resolve({ cmd: finalCommand, args }); return Promise.resolve({ cmd: finalCommand, args });
} catch (error) { } catch (error) {