[refactor] DRY up this command_mode business