adds command line functionality.  Needs optimization!

Needs some optimization work... and some significant refactoring.....  but it works OK for CMHS.  It's too complicated and magical maybe... and ugly... but can work.