cli: abstract subcommand finding into a new function