diff --git a/sources/Commands/Command.uc b/sources/Commands/Command.uc index acbfe1c..83df47b 100644 --- a/sources/Commands/Command.uc +++ b/sources/Commands/Command.uc @@ -97,7 +97,11 @@ enum ParameterType // Parses into `HashTable` CPT_Object, // Parses into `ArrayList` - CPT_Array + CPT_Array, + // Parses into any JSON value + CPT_JSON, + // Parses into an array of specified players + CPT_PLAYERS }; /** diff --git a/sources/Commands/CommandDataBuilder.uc b/sources/Commands/CommandDataBuilder.uc index 66dbbe7..b2057c8 100644 --- a/sources/Commands/CommandDataBuilder.uc +++ b/sources/Commands/CommandDataBuilder.uc @@ -973,6 +973,122 @@ public final function CommandDataBuilder ParamArrayList( return self; } +/** + * Adds new JSON value parameter (required or optional depends on whether + * `RequireTarget()` call happened) to the currently selected + * sub-command / option. + * + * Only fails if provided `name` is `none`. + * + * @param name Name of the parameter, will be copied + * (as it would appear in the generated help info). + * @param variableName Name of the variable that will store this + * parameter's value in `HashTable` after user's command input + * is parsed. Provided value will be copied. + * If left `none`, - will coincide with `name` parameter. + * @return Returns the caller `CommandDataBuilder` to allow for + * method chaining. + */ +public final function CommandDataBuilder ParamJSON( + BaseText name, + optional BaseText variableName) +{ + if (name == none) { + return self; + } + PushParameter(NewParameter(name, CPT_JSON, false, variableName)); + return self; +} + +/** + * Adds new parameter for list of JSON values (required or optional depends on + * whether `RequireTarget()` call happened) to the currently selected + * sub-command / option. + * + * Only fails if provided `name` is `none`. + * + * @param name Name of the parameter, will be copied + * (as it would appear in the generated help info). + * @param variableName Name of the variable that will store this + * parameter's value in `HashTable` after user's command input + * is parsed. Provided value will be copied. + * If left `none`, - will coincide with `name` parameter. + * @return Returns the caller `CommandDataBuilder` to allow for + * method chaining. + */ +public final function CommandDataBuilder ParamJSONList( + BaseText name, + optional BaseText variableName) +{ + if (name == none) { + return self; + } + PushParameter(NewParameter(name, CPT_JSON, true, variableName)); + return self; +} + +/** + * Adds new players value parameter (required or optional depends on whether + * `RequireTarget()` call happened) to the currently selected + * sub-command / option. + * + * Players parameter is a parameter that allows one to specify a list of + * players through special selectors, the same way one does for + * targeted commands. + * + * Only fails if provided `name` is `none`. + * + * @param name Name of the parameter, will be copied + * (as it would appear in the generated help info). + * @param variableName Name of the variable that will store this + * parameter's value in `HashTable` after user's command input + * is parsed. Provided value will be copied. + * If left `none`, - will coincide with `name` parameter. + * @return Returns the caller `CommandDataBuilder` to allow for + * method chaining. + */ +public final function CommandDataBuilder ParamPlayers( + BaseText name, + optional BaseText variableName) +{ + if (name == none) { + return self; + } + PushParameter(NewParameter(name, CPT_PLAYERS, false, variableName)); + return self; +} + +/** + * Adds new parameter for list of players values (required or optional depends + * on whether `RequireTarget()` call happened) to the currently selected + * sub-command / option. + * + * Players parameter is a parameter that allows one to specify a list of + * players through special selectors, the same way one does for + * targeted commands. + * + * Only fails if provided `name` is `none`. + * + * @param name Name of the parameter, will be copied + * (as it would appear in the generated help info). + * @param variableName Name of the variable that will store this + * parameter's value in `HashTable` after user's command input + * is parsed. Provided value will be copied. + * If left `none`, - will coincide with `name` parameter. + * @return Returns the caller `CommandDataBuilder` to allow for + * method chaining. + */ +public final function CommandDataBuilder ParamPlayersList( + BaseText name, + optional BaseText variableName) +{ + if (name == none) { + return self; + } + PushParameter(NewParameter(name, CPT_PLAYERS, true, variableName)); + return self; +} + defaultproperties { errLongNameTooShort = (l=LOG_Error,m="Command `%1` is trying to register an option with a name that is way too short (<2 characters). Option will be discarded: %2")