Skip to content

Commit

Permalink
Fix alias finding if user is not logged in (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Feb 29, 2020
1 parent 85d6797 commit abae820
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.D/1360.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the alias finding routine when user is not logged in.
5 changes: 4 additions & 1 deletion neuromation/cli/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def format_help_text(


async def find_alias(root: Root, cmd_name: str) -> Optional[click.Command]:
client = await root.init_client()
try:
client = await root.init_client()
except ConfigError:
return None
config = await client.config.get_user_config()
alias = config.get("alias", {}).get(cmd_name)
if alias is None:
Expand Down
18 changes: 18 additions & 0 deletions tests/cli/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,21 @@ async def test_list_aliases(root: Root, nmrc_path: Path) -> None:
lst = await list_aliases(root)
names = [cmd.name for cmd in lst]
assert names == ["lsl", "user-cmd"]


async def test_find_alias_without_config(tmp_path: Path) -> None:
root = Root(
color=False,
tty=False,
terminal_size=(80, 24),
disable_pypi_version_check=True,
network_timeout=60,
config_path=tmp_path,
verbosity=0,
trace=False,
trace_hide_token=True,
command_path="",
command_params=[],
skip_gmp_stats=True,
)
assert await find_alias(root, "unknown-cmd") is None

0 comments on commit abae820

Please sign in to comment.