def _list(): """Show all existing stored profiles.""" profiles = cliprofile.get_all_profiles() if not profiles: raise Code42CLIError("No existing profile.", help=CREATE_PROFILE_HELP) for c42profile in profiles: echo(str(c42profile))
def test_get_all_profiles_returns_expected_profile_list(config_accessor): config_accessor.get_all_profiles.return_value = [ create_mock_profile("one"), create_mock_profile("two"), ] profiles = cliprofile.get_all_profiles() assert len(profiles) == 2 assert profiles[0].name == "one" assert profiles[1].name == "two"
def _select_profile_from_prompt(): """Set the default profile from user input.""" profiles = cliprofile.get_all_profiles() profile_names = [profile_choice.name for profile_choice in profiles] choices = PromptChoice(profile_names) choices.print_choices() prompt_message = "Input the number of the profile you wish to use" profile_name = click.prompt(prompt_message, type=choices) _set_default_profile(profile_name)
def delete_all(): """Deletes all profiles and saved passwords (if any).""" existing_profiles = cliprofile.get_all_profiles() if existing_profiles: message = ( "\nAre you sure you want to delete the following profiles?\n\t{}" "\n\nThis will also delete any stored passwords and checkpoints. (y/n): " ).format("\n\t".join([c42profile.name for c42profile in existing_profiles])) if does_user_agree(message): for profile_obj in existing_profiles: cliprofile.delete_profile(profile_obj.name) echo("Profile '{}' has been deleted.".format(profile_obj.name)) else: echo("\nNo profiles exist. Nothing to delete.")