v1.4.5
This commit is contained in:
parent
c669d60428
commit
aa7fe8643c
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navy.gif/commandparser",
|
||||
"version": "1.4.4",
|
||||
"version": "1.4.5",
|
||||
"description": "Parser meant to parse commands and their options for discord bots",
|
||||
"author": "Navy.gif",
|
||||
"license": "MIT",
|
||||
|
@ -10,6 +10,7 @@ abstract class Command implements ICommand {
|
||||
name: string;
|
||||
aliases: string[];
|
||||
options: CommandOption[];
|
||||
help?: string;
|
||||
|
||||
constructor (def: CommandDefinition) {
|
||||
|
||||
@ -18,9 +19,10 @@ abstract class Command implements ICommand {
|
||||
|
||||
if (!def.name)
|
||||
throw new Error('Missing name for command');
|
||||
this.name = def.name;
|
||||
|
||||
this.name = def.name;
|
||||
this.aliases = def.aliases || [];
|
||||
this.help = def.help;
|
||||
|
||||
// Add a built-in help flag to any non-subcommand option
|
||||
this.options = [
|
||||
|
@ -8,6 +8,7 @@ class CommandOption implements ICommandOption {
|
||||
[key: string]: unknown;
|
||||
name: string;
|
||||
aliases: string[];
|
||||
help?: string;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
options: CommandOption[];
|
||||
type: OptionType;
|
||||
@ -35,6 +36,7 @@ class CommandOption implements ICommandOption {
|
||||
this.strict = def.strict || false;
|
||||
this.type = def.type ?? OptionType.STRING;
|
||||
this.flag = def.flag || false;
|
||||
this.help = def.help;
|
||||
|
||||
this.options = [];
|
||||
if (SUB.includes(this.type))
|
||||
|
@ -10,6 +10,7 @@ interface ICommand {
|
||||
name: string,
|
||||
aliases: string[]
|
||||
options: CommandOption[]
|
||||
help?: string
|
||||
|
||||
get subcommands(): SubcommandOption[]
|
||||
|
||||
@ -27,6 +28,7 @@ type CommandDefinition = {
|
||||
name: string;
|
||||
aliases?: string[];
|
||||
options?: (CommandOptionDefinition | CommandOption)[];
|
||||
help?: string
|
||||
}
|
||||
|
||||
export { ICommand, CommandDefinition };
|
||||
|
@ -72,6 +72,7 @@ type ParseResult = {
|
||||
type CommandOptionDefinition = {
|
||||
name: string;
|
||||
aliases?: string[];
|
||||
help?: string;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
options?: (CommandOptionDefinition|CommandOption)[];
|
||||
type?: OptionType;
|
||||
@ -99,6 +100,7 @@ interface ICommandOption {
|
||||
name: string;
|
||||
// Optional alises
|
||||
aliases: string[];
|
||||
help?: string;
|
||||
|
||||
// Sub options
|
||||
options: CommandOption[];
|
||||
|
@ -18,4 +18,5 @@ const command = new Command({
|
||||
const parser = new Parser({ commands: [command], prefix: '', debug: true });
|
||||
parser.on('debug', console.log)
|
||||
console.log(await parser.parseMessage('create code -a 1'));
|
||||
console.log(await parser.parseMessage('create code --help'))
|
||||
console.log(await parser.parseMessage('create code --help'));
|
||||
console.log(await parser.parseMessage('create --help'));
|
Loading…
Reference in New Issue
Block a user