Is it possible to prevent a command from being executed inside the PreCommand interceptor? What’s the best way to do that?
IE: check if certain conditions exist. If they don’t, bypass execution of the command.
Thanks,
Joel
Is it possible to prevent a command from being executed inside the PreCommand interceptor? What’s the best way to do that?
IE: check if certain conditions exist. If they don’t, bypass execution of the command.
Thanks,
Joel
I don’t think so but I suppose that could be added. If you wanted, you could just throw an exception. If you throw a user cancelled exception, it would exit and just say “cancelled”. What is your use case for this?
Hi Brad,
We’ve an internal CommandBox module that includes some commands to help facilitate a really old and outdated release process. We want to prevent some commands from being executed unintentionally/prematurely by users who are unfamiliar with how the process works. One way we talked about doing that was through the preCommand interceptor. Since interceptData is passed by reference, I thought that it might be possible to prevent a command from executing by removing or modifying part of that struct.
We are not short on solutions for the problem. The onCommand interceptor was an attractive option because it would reduce the amount of work required.
Thanks for the response!
Joel
Yep, if you just want to stop it from running, I’d just do something like this in your preCommand interceptor:
throw( message=arguments.message, detail=arguments.detail, type=“commandException”);
You might also get some good mileage out of just adding something that makes the user confirm first:
if( force || confirm( "Are you sure?? " ) ) {
// Do the thing
} else {
error( “Cancelled” );
}