-
Notifications
You must be signed in to change notification settings - Fork 0
Applying custom rules when executing commands
JF Blouin edited this page Apr 12, 2019
·
3 revisions
You may include custom rules / logic when executing commands. For instance, you may have a parameter only required in case another has a specific value. For this, you need to write the rule in code.
Derive a class from ParameterRuleAttribute, located in the CommandLineEngine.Attributes namespace, in order to create a rule in your language of choice.
Then decorate the method parameter you wish to apply the rule. The rule will be evaluated when your command is executed.
Example:
public sealed class ParameterRuleTest : CommandLineEngine.Attributes.ParameterRuleAttribute
{
public override bool Evaluate(InputArguments inputArguments, OperationResult operationResult)
{
return true;
}
}
[CommandLineEngine.Attributes.Command()]
static int SingleCommand([ParameterRuleTest] string parameter)
{
}
``Need more information or have an idea? Do not hesitate to reach out or submit a pull request.