From aa7fe8643c0f539bf43631067465bd8471565aa8 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 5 May 2023 18:29:54 +0300 Subject: [PATCH] v1.4.5 --- package.json | 2 +- src/classes/Command.ts | 4 +++- src/classes/CommandOption.ts | 2 ++ src/interfaces/Command.ts | 2 ++ src/interfaces/CommandOption.ts | 2 ++ tests/playground.js | 3 ++- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ce37ecf..610db15 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/classes/Command.ts b/src/classes/Command.ts index 48c72f1..cf2b21a 100644 --- a/src/classes/Command.ts +++ b/src/classes/Command.ts @@ -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.aliases = def.aliases || []; + this.help = def.help; // Add a built-in help flag to any non-subcommand option this.options = [ diff --git a/src/classes/CommandOption.ts b/src/classes/CommandOption.ts index 9b688fe..d14e11d 100644 --- a/src/classes/CommandOption.ts +++ b/src/classes/CommandOption.ts @@ -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)) diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index 7fadf50..e2c96c8 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -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 }; diff --git a/src/interfaces/CommandOption.ts b/src/interfaces/CommandOption.ts index 6b1cdff..4701a9a 100644 --- a/src/interfaces/CommandOption.ts +++ b/src/interfaces/CommandOption.ts @@ -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[]; diff --git a/tests/playground.js b/tests/playground.js index e024e82..30f6b02 100644 --- a/tests/playground.js +++ b/tests/playground.js @@ -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')) \ No newline at end of file +console.log(await parser.parseMessage('create code --help')); +console.log(await parser.parseMessage('create --help')); \ No newline at end of file