From cd5d38b082222a62e421eba5c4ab474b0ce9e832 Mon Sep 17 00:00:00 2001 From: Marcel Menzel Date: Sat, 22 Sep 2018 00:25:05 +0200 Subject: [PATCH] add (static) default value support for types --- lib/commandHandler.js | 6 +++++- types/README.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/commandHandler.js b/lib/commandHandler.js index 7325cb7..2d4220c 100644 --- a/lib/commandHandler.js +++ b/lib/commandHandler.js @@ -820,7 +820,11 @@ class CommandHandler { parsedArguments.push(currentArgument.default); } } else if (argumentParser.default) { - parsedArguments.push(await argumentParser.default(context)); + if (typeof argumentParser.default === 'function') { + parsedArguments.push(await argumentParser.default(context)); + } else { + parsedArguments.push(argumentParser.default); + } } else { parsedArguments.push(undefined); } diff --git a/types/README.md b/types/README.md index 499f9f6..6768667 100644 --- a/types/README.md +++ b/types/README.md @@ -8,5 +8,5 @@ This folder contains the files for each type the argument parser will validate t * `value` the input word as string (or a multi-word string if entered by the user) * `argument` argument options that have been set in the respective command file * `context` the context object, see the [context documentation](../context.md) -- `default()` the function that will be executed if `optional` has been set to true in the command file, passed arguments: +- `default()` a value or a function that will be executed if `optional` has been set to true in the command file, passed arguments: * `context` the context object, see `context.md`