refactor, clean up and break out cli options into function

Sorry about the diff. It's hard to see what happened because I got rid of indentation and at the same time reordered functions so the order in .h and .cc match. Probably easier if you just check ldb.h and ldb.cc manually.