Lots of cleanup and more generic commands

Started to extract some of the generic behavior across all commands into
`execute_main` so that the commands themselves just need to operate
against structs (for JSON in and Flags)