Skip to content

Commit

Permalink
Merge pull request #31 from haginara/fix-update-config-2
Browse files Browse the repository at this point in the history
Fixed the update command
  • Loading branch information
haginara authored Jan 17, 2024
2 parents 2fa4773 + c026b10 commit 4564693
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ssh_config/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_config(ctx, name):
@click.argument("name")
@click.argument("attributes", metavar="<Attribute=Value>", nargs=-1)
@click.pass_context
def add_config(ctx, name, attributes):
def add_config(ctx, name: str, attributes: list[str]):
"""Add SSH Config into config file"""
config = ctx.obj["config"]
if config.exists(name):
Expand Down Expand Up @@ -234,21 +234,22 @@ def add_config(ctx, name, attributes):
@click.argument("name")
@click.argument("attributes", nargs=-1, metavar="<key=value>")
@click.pass_context
def update_config(ctx, name, attributes):
def update_config(ctx, name: str, attributes: list[str]):
"""Update the ssh Host config Attribute key=value format"""
config = ctx.obj["config"]

if not config.exists(name):
click.secho(f"{name} does not exist, use `update` instead of `add`", fg="red")
raise SystemExit

host = config.get(name)
host: Host = config.get(name)
print(type(host))
click.echo(host)
click.echo("=" * 25)
for attribute in attributes:
try:
key, value = attribute.split("=")
for attr, _ in Host.attrs:
for attr in host.attributes():
if attr.lower() == key.lower():
config.update(name, {attr: value})
break
Expand Down
2 changes: 1 addition & 1 deletion ssh_config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def exists(self, name: str):
return False
return True

def get(self, name: str):
def get(self, name: str) -> Host:
"""Get Host with name
Args:
name (str): host name
Expand Down

0 comments on commit 4564693

Please sign in to comment.