mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Elevate --verbose to top-level option (#590)
* Elevate --verbose to be usable for all commands * Fix tests
This commit is contained in:
parent
b66347116f
commit
1d5a9c35f4
32
kasa/cli.py
32
kasa/cli.py
@ -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)
|
||||||
|
|
||||||
|
@ -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",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user