Skip to content

Commit

Permalink
feat: Add signature & signatures functions to Command class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Sep 3, 2021
1 parent 0d0389c commit 38b1472
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/classes/commands/Command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {GuildChannel, GuildMember, Message, Permissions, PermissionString, Snowflake, TextChannel, User} from 'discord.js';
import {CommandHandler} from '../../CommandHandler';
import {isOwner, isPermission, Logger} from '../../utils';
import {Argument, ArgumentType, CommandArgument} from '../arguments';
import {Argument, CommandArgument} from '../arguments';
import {CommandContext, SubCommandContext} from '../contexts';
import {CommandError, CommandErrorBuilder, CommandErrorType} from '../errors';
import {RunSubCommandFunction, SubCommandOptions} from './SubCommand';
Expand Down Expand Up @@ -389,7 +389,7 @@ export abstract class Command {
let signature = '';
signature += commandArgument.isSkipable ? '[' : '<';
signature += commandArgument.name;
if (commandArgument.showTypeInSignature) signature += `: ${ArgumentType[commandArgument.type].toLowerCase()}`;
if (commandArgument.showTypeInSignature) signature += `: ${commandArgument.type.toLowerCase()}`;
if (commandArgument.defaultValue && commandArgument.showDefaultValueInSignature) signature += `= ${commandArgument.defaultValue}`;
signature += commandArgument.isSkipable ? ']' : '>';
result += ` ${signature}`;
Expand All @@ -398,6 +398,12 @@ export abstract class Command {
return result;
}

public signatures() {
let result = `${this.signature()}\n`;
result += this.subCommands.map(subCommand => `${this.name} ${subCommand.signature()}`).join(`\n`);
return result;
}

/**
* Validate a command, returning an error if any of the validation methods are not valid.
*
Expand Down

0 comments on commit 38b1472

Please sign in to comment.