Skip to content

Commit d27f6db

Browse files
author
Juliya Smith
authored
Chore/profile name in profile cmds (#31)
1 parent 590a43d commit d27f6db

6 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/code42cli/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _create_auto_args_config(arg_position, key, argspec, num_args, num_kw_args):
7575
param_name = key.replace(u"_", u"-")
7676
difference = num_args - num_kw_args
7777
last_positional_arg_idx = difference - 1
78-
# postional arguments will come first, so if the arg position
78+
# positional arguments will come first, so if the arg position
7979
# is greater than the index of the last positional arg, it's a kwarg.
8080
if arg_position > last_positional_arg_idx:
8181
# this is a keyword arg, treat it as an optional cli arg.

src/code42cli/cmds/profile.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from getpass import getpass
44

55
import code42cli.profile as cliprofile
6-
from code42cli.args import PROFILE_HELP
6+
from code42cli.args import PROFILE_HELP, ArgConfig
77
from code42cli.commands import Command
88
from code42cli.sdk_client import validate_connection
99
from code42cli.util import does_user_agree, print_error, print_no_existing_profile_message
@@ -18,7 +18,7 @@ def load_subcommands():
1818
u"Print the details of a profile.",
1919
u"{} {}".format(usage_prefix, u"show <optional-args>"),
2020
handler=show_profile,
21-
arg_customizer=_load_profile_description,
21+
arg_customizer=_load_optional_profile_description,
2222
)
2323

2424
list_all = Command(
@@ -40,7 +40,7 @@ def load_subcommands():
4040
u"Change the stored password for a profile.",
4141
u"{} {}".format(usage_prefix, u"reset-pw <optional-args>"),
4242
handler=prompt_for_password_reset,
43-
arg_customizer=_load_profile_description,
43+
arg_customizer=_load_optional_profile_description,
4444
)
4545

4646
create = Command(
@@ -62,9 +62,9 @@ def load_subcommands():
6262
return [show, list_all, use, reset_pw, create, update]
6363

6464

65-
def show_profile(profile=None):
65+
def show_profile(name=None):
6666
"""Prints the given profile to stdout."""
67-
c42profile = cliprofile.get_profile(profile)
67+
c42profile = cliprofile.get_profile(name)
6868
print(u"\n{0}:".format(c42profile.name))
6969
print(u"\t* username = {}".format(c42profile.username))
7070
print(u"\t* authority url = {}".format(c42profile.authority_url))
@@ -79,15 +79,15 @@ def create_profile(profile, server, username, disable_ssl_errors=False):
7979
_prompt_for_allow_password_set(profile)
8080

8181

82-
def update_profile(profile=None, server=None, username=None, disable_ssl_errors=None):
83-
profile = cliprofile.get_profile(profile)
82+
def update_profile(name=None, server=None, username=None, disable_ssl_errors=None):
83+
profile = cliprofile.get_profile(name)
8484
cliprofile.update_profile(profile.name, server, username, disable_ssl_errors)
8585
_prompt_for_allow_password_set(profile.name)
8686

8787

88-
def prompt_for_password_reset(profile=None):
88+
def prompt_for_password_reset(name=None):
8989
"""Securely prompts for your password and then stores it using keyring."""
90-
c42profile = cliprofile.get_profile(profile)
90+
c42profile = cliprofile.get_profile(name)
9191
new_password = getpass()
9292
_validate_connection(c42profile.authority_url, c42profile.username, new_password)
9393
cliprofile.set_password(new_password, c42profile.name)
@@ -117,20 +117,20 @@ def use_profile(profile):
117117
cliprofile.switch_default_profile(profile)
118118

119119

120-
def _load_profile_description(argument_collection):
121-
profile = argument_collection.arg_configs[u"profile"]
120+
def _load_optional_profile_description(argument_collection):
121+
profile = argument_collection.arg_configs[u"name"]
122+
profile.add_short_option_name(u"-n")
122123
profile.set_help(PROFILE_HELP)
123124

124125

125126
def _load_profile_create_descriptions(argument_collection):
126127
profile = argument_collection.arg_configs[u"profile"]
127-
profile.set_help(u"The name to give the profile being created.")
128+
profile.set_help(PROFILE_HELP)
128129
_load_profile_settings_descriptions(argument_collection)
129130

130131

131132
def _load_profile_update_descriptions(argument_collection):
132-
profile = argument_collection.arg_configs[u"profile"]
133-
profile.set_help(u"The name to give the profile being updated.")
133+
_load_optional_profile_description(argument_collection)
134134
_load_profile_settings_descriptions(argument_collection)
135135
argument_collection.arg_configs[u"server"].add_short_option_name(u"-s")
136136
argument_collection.arg_configs[u"username"].add_short_option_name(u"-u")

src/code42cli/profile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
print_no_existing_profile_message,
88
)
99

10+
1011
class Code42Profile(object):
1112
def __init__(self, profile):
1213
self._profile = profile

src/code42cli/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def print_set_default_profile_help(existing_profiles):
6666
print(
6767
u"\nNo default profile set.\n",
6868
u"\nUse the --profile flag to specify which profile to use.\n",
69-
u"\nTo set the default profile (used whenever --profile argument is not provided), use:"
69+
u"\nTo set the default profile (used whenever --profile argument is not provided), use:",
7070
)
7171
print_bold(u"\tcode42 profile use <profile-name>")
7272
print(u"\nExisting profiles:")

tests/cmds/test_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_update_profile_updates_existing_profile(
122122
profile.name = name
123123
mock_cliprofile_namespace.get_profile.return_value = profile
124124

125-
profilecmd.update_profile(name, "bar", "baz", True)
125+
profilecmd.update_profile(name=name, server="bar", username="baz", disable_ssl_errors=True)
126126
mock_cliprofile_namespace.update_profile.assert_called_once_with(name, "bar", "baz", True)
127127

128128

tests/test_profile.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_get_profile_returns_expected_profile(config_accessor):
5858
profile = cliprofile.get_profile("testprofilename")
5959
assert profile.name == "testprofilename"
6060

61+
6162
def test_get_profile_when_config_accessor_throws_exits(config_accessor):
6263
config_accessor.get_profile.side_effect = NoConfigProfileError()
6364
with pytest.raises(SystemExit):
@@ -76,18 +77,20 @@ def test_default_profile_exists_when_not_exists_returns_false(config_accessor):
7677
assert not cliprofile.default_profile_exists()
7778

7879

79-
def test_validate_default_profile_prints_set_default_help_when_no_valid_default_but_another_profile_exists(capsys, config_accessor):
80+
def test_validate_default_profile_prints_set_default_help_when_no_valid_default_but_another_profile_exists(
81+
capsys, config_accessor
82+
):
8083
config_accessor.get_profile.side_effect = NoConfigProfileError()
81-
config_accessor.get_all_profiles.return_value = [
82-
MockSection("thisprofilexists")
83-
]
84+
config_accessor.get_all_profiles.return_value = [MockSection("thisprofilexists")]
8485
with pytest.raises(SystemExit):
8586
cliprofile.validate_default_profile()
8687
capture = capsys.readouterr()
8788
assert "No default profile set." in capture.out
8889

8990

90-
def test_validate_default_profile_prints_create_profile_help_when_no_valid_default_and_no_other_profiles_exists(capsys, config_accessor):
91+
def test_validate_default_profile_prints_create_profile_help_when_no_valid_default_and_no_other_profiles_exists(
92+
capsys, config_accessor
93+
):
9194
config_accessor.get_profile.side_effect = NoConfigProfileError()
9295
config_accessor.get_all_profiles.return_value = []
9396
with pytest.raises(SystemExit):

0 commit comments

Comments
 (0)