MI: extract command completion logic from complete_command()