You would register an applet using the CLI event detector with the "enter" keyword. The enter keyword tells the parser not to deal with the command. This will allow you to create your own command. For example:
event manager applet test
event cli pattern "^show foobar state" enter
action 1.0 puts "FOO!"