Move the diagnostic handler up a level

Now either the command line or test interface will be able to handle
diagnostics differently.