Elevate --verbose to top-level option (#590)

* Elevate --verbose to be usable for all commands

* Fix tests
This commit is contained in:
Teemu R 2023-12-29 16:04:41 +01:00 committed by GitHub
parent b66347116f
commit 1d5a9c35f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions

View File

@ -128,7 +128,23 @@ def json_formatter_cb(result, **kwargs):
show_default=True, show_default=True,
help="The broadcast address to be used for discovery.", help="The broadcast address to be used for discovery.",
) )
@click.option("-d", "--debug", envvar="KASA_DEBUG", default=False, is_flag=True) @click.option(
"-v",
"--verbose",
envvar="KASA_VERBOSE",
required=False,
default=False,
is_flag=True,
help="Be more verbose on output",
)
@click.option(
"-d",
"--debug",
envvar="KASA_DEBUG",
default=False,
is_flag=True,
help="Print debug output",
)
@click.option( @click.option(
"--type", "--type",
envvar="KASA_TYPE", envvar="KASA_TYPE",
@ -147,6 +163,7 @@ def json_formatter_cb(result, **kwargs):
envvar="KASA_TIMEOUT", envvar="KASA_TIMEOUT",
default=5, default=5,
required=False, required=False,
show_default=True,
help="Timeout for device communications.", help="Timeout for device communications.",
) )
@click.option( @click.option(
@ -154,6 +171,7 @@ def json_formatter_cb(result, **kwargs):
envvar="KASA_DISCOVERY_TIMEOUT", envvar="KASA_DISCOVERY_TIMEOUT",
default=3, default=3,
required=False, required=False,
show_default=True,
help="Timeout for discovery.", help="Timeout for discovery.",
) )
@click.option( @click.option(
@ -178,6 +196,7 @@ async def cli(
port, port,
alias, alias,
target, target,
verbose,
debug, debug,
type, type,
json, json,
@ -307,21 +326,14 @@ async def join(dev: SmartDevice, ssid, password, keytype):
@cli.command() @cli.command()
@click.option(
"--verbose",
envvar="KASA_VERBOSE",
required=False,
default=False,
is_flag=True,
help="Be more verbose on output",
)
@click.pass_context @click.pass_context
async def discover(ctx, verbose): async def discover(ctx):
"""Discover devices in the network.""" """Discover devices in the network."""
target = ctx.parent.params["target"] target = ctx.parent.params["target"]
username = ctx.parent.params["username"] username = ctx.parent.params["username"]
password = ctx.parent.params["password"] password = ctx.parent.params["password"]
timeout = ctx.parent.params["discovery_timeout"] timeout = ctx.parent.params["discovery_timeout"]
verbose = ctx.parent.params["verbose"]
credentials = Credentials(username, password) credentials = Credentials(username, password)

View File

@ -236,8 +236,8 @@ async def test_discover(discovery_mock, mocker):
"foo", "foo",
"--password", "--password",
"bar", "bar",
"discover",
"--verbose", "--verbose",
"discover",
], ],
) )
assert res.exit_code == 0 assert res.exit_code == 0
@ -255,8 +255,8 @@ async def test_discover_unsupported(unsupported_device_info):
"foo", "foo",
"--password", "--password",
"bar", "bar",
"discover",
"--verbose", "--verbose",
"discover",
], ],
) )
assert res.exit_code == 0 assert res.exit_code == 0
@ -306,8 +306,8 @@ async def test_discover_auth_failed(discovery_mock, mocker):
"foo", "foo",
"--password", "--password",
"bar", "bar",
"discover",
"--verbose", "--verbose",
"discover",
], ],
) )