Refactor of #7887

Closes #7887

Thanks @rhatdan for most of the work

@rhatdan I changed behavior for `CmdLogin`, `CmdLogout`, `CmdPs`. Can you double check it's correct?
It would definitely be easier to understand if `CheckArgs` just returned the diagnostic message, but that's really up to you it's not significant.