mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-24 21:50:21 +00:00
Show an error if both --alias and --host are defined (#513)
Display an error if both --alias and --host are defined to avoid ambiguous target device: ``` ❯ kasa --host 123 --alias 123 state Usage: kasa [OPTIONS] COMMAND [ARGS]... Try 'kasa --help' for help. Error: Use either --alias or --host, not both. ``` Also, use `click.BadOptionUsage` consistently for other errors, like when only `--username` or `--password` is given.
This commit is contained in:
@@ -209,6 +209,9 @@ async def cli(
|
||||
if ctx.invoked_subcommand == "discover":
|
||||
return
|
||||
|
||||
if alias is not None and host is not None:
|
||||
raise click.BadOptionUsage("alias", "Use either --alias or --host, not both.")
|
||||
|
||||
if alias is not None and host is None:
|
||||
echo(f"Alias is given, using discovery to find host {alias}")
|
||||
host = await find_host_from_alias(alias=alias, target=target)
|
||||
@@ -219,8 +222,9 @@ async def cli(
|
||||
return
|
||||
|
||||
if bool(password) != bool(username):
|
||||
echo("Using authentication requires both --username and --password")
|
||||
return
|
||||
raise click.BadOptionUsage(
|
||||
"username", "Using authentication requires both --username and --password"
|
||||
)
|
||||
|
||||
credentials = Credentials(username=username, password=password)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user