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

View File

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