While working on the people profilecardproperty add command, I had to implement unknown options in such a way that they would only be allowed when the command would be executed on a customAttribute.
That leads to extra code in the validation function that can also be moved to the central CLI engine.
A quite simple fix actually:
Let's pass the args to the allowUnknownOptions function, so we can optionally allow them.
In Command.ts:
private async validateUnknownOptions(args: CommandArgs, command: CommandInfo): Promise<string | boolean> {
if (this.allowUnknownOptions(args))
{
return true;
}
//...
}
In the example people profilecardproperty add command:
public allowUnknownOptions(args: CommandArgs): boolean | undefined {
return args.name.toLowerCase().startsWith('customattribute');
}
The only downside of this method is: you can't give a custom message about why you would allow unknown options in one case, while blocking them in another. Unless we would allow to return a string message as well:
public allowUnknownOptions(args: CommandArgs): boolean | string | undefined {
return !args.name.toLowerCase().startsWith('customattribute') ? 'you can only use unknown options when specifying a customAttribute for the name option' : true
}
While working on the people profilecardproperty add command, I had to implement unknown options in such a way that they would only be allowed when the command would be executed on a customAttribute.
That leads to extra code in the validation function that can also be moved to the central CLI engine.
A quite simple fix actually:
Let's pass the
argsto theallowUnknownOptionsfunction, so we can optionally allow them.In Command.ts:
In the example
people profilecardproperty addcommand:The only downside of this method is: you can't give a custom message about why you would allow unknown options in one case, while blocking them in another. Unless we would allow to return a string message as well: