Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context validation rules builder class #126

Open
koloml opened this issue Aug 19, 2022 · 0 comments
Open

Context validation rules builder class #126

koloml opened this issue Aug 19, 2022 · 0 comments
Labels
Type-Enhancement New feature or request

Comments

@koloml
Copy link
Contributor

koloml commented Aug 19, 2022

Is your feature request related to a problem? Please describe.
Currently, some of the commands contain special object with validation rules in the static property. This property is used by CommandContextValidator to check if context fits the rules. Main issue of this property is that it's documented in JSDoc and without this comment presented, this property will not give any hints about available and valid properties.

Describe the solution you'd like
I think it'll be better if these rules will be generated using some sort of builder class with the methods for all available options. Usage of this class might look like this:

class ExampleCommand extends BaseCommand {
  // Logic of the command
  
  static validators = new ValidatorBuilder()
    .requireCallerPermission("ADMINISTRATOR")
    .maxArguments(2)
    .minArguments(1)
    .argumentVariants(['option1', 'option2'])
    .argumentRegexp(/^option[12]$/)
}

With class like this it'll be easier to implement new features for the context validation and keep track of already existing ones.

Describe alternatives you've considered

Additional context
Example of the command with validators:
https://github.com/thecorecity/cognitum/blob/master/lib/commands/guild/LogSettingsCommand.js

@koloml koloml added the Type-Enhancement New feature or request label Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type-Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant