From 54423a93958a1c06a92d6ebfcf8a30bc90574642 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 28 Mar 2024 21:07:11 +0200 Subject: [PATCH] Remove outdated code --- src/Parser.ts | 1 - src/classes/Command.ts | 11 +---------- src/classes/CommandOption.ts | 8 -------- tests/playground.js | 17 +++++++++++++++++ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Parser.ts b/src/Parser.ts index 8008d91..19e09af 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -73,7 +73,6 @@ class Parser extends EventEmitter #globalFlags: CommandOption[]; #allowIncompleteReturn: string[]; - constructor ({ commands, prefix, debug = false, resolver, allowDefaultOnRequired, globalFlags = [], allowIncompleteReturn }: ParserOptions) { diff --git a/src/classes/Command.ts b/src/classes/Command.ts index 79619f0..77baae9 100644 --- a/src/classes/Command.ts +++ b/src/classes/Command.ts @@ -23,16 +23,7 @@ abstract class Command implements ICommand this.aliases = def.aliases || []; this.help = def.help; - // Add a built-in help flag to any non-subcommand option - this.options = [ - new CommandOption({ - name: 'help', - type: OptionType.BOOLEAN, - flag: true, - valueOptional: true, - defaultValue: true - }) - ]; + this.options = [ ]; for (const opt of def.options || []) { diff --git a/src/classes/CommandOption.ts b/src/classes/CommandOption.ts index df9d4d6..eb7e8af 100644 --- a/src/classes/CommandOption.ts +++ b/src/classes/CommandOption.ts @@ -39,14 +39,6 @@ class CommandOption implements ICommandOption this.help = def.help; this.options = []; - if (SUB.includes(this.type)) - this.options.push(new CommandOption({ - name: 'help', - type: OptionType.BOOLEAN, - flag: true, - valueOptional: true, - defaultValue: true - })); for (const opt of def.options || []) { diff --git a/tests/playground.js b/tests/playground.js index a359381..fa31353 100644 --- a/tests/playground.js +++ b/tests/playground.js @@ -1,6 +1,20 @@ import { Parser, Command, OptionType } from '../build/esm/index.js'; const commands = [ + new Command({ + name: 'test', + options: [{ + name: 'sub', + type: OptionType.SUB_COMMAND, + options: [{ + name: 'flag', + type: OptionType.BOOLEAN, + defaultValue: true, + valueOptional: true, + flag: true + }] + }] + }), new Command({ name: 'create', options: [{ @@ -52,6 +66,7 @@ const commands = [ }) ]; +const [first] = commands; const parser = new Parser({ commands, prefix: '', debug: true, globalFlags: [{ @@ -67,6 +82,8 @@ 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 --help')); +console.log((await parser.parseMessage('test sub --help'))); +console.log(first.subcommand('sub').options); console.log((await parser.parseMessage('create code')));