mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-15 06:38:42 +00:00
Add 'shell' command to cli (#738)
* Add 'shell' command to cli * Add test * Add ptpython as optional dep
This commit is contained in:
21
kasa/cli.py
21
kasa/cli.py
@@ -1081,5 +1081,26 @@ async def update_credentials(dev, username, password):
|
||||
return await dev.update_credentials(username, password)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@pass_dev
|
||||
async def shell(dev: Device):
|
||||
"""Open interactive shell."""
|
||||
echo("Opening shell for %s" % dev)
|
||||
from ptpython.repl import embed
|
||||
|
||||
logging.getLogger("parso").setLevel(logging.WARNING) # prompt parsing
|
||||
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
||||
loop = asyncio.get_event_loop()
|
||||
try:
|
||||
await embed(
|
||||
globals=globals(),
|
||||
locals=locals(),
|
||||
return_asyncio_coroutine=True,
|
||||
patch_stdout=True,
|
||||
)
|
||||
except EOFError:
|
||||
loop.stop()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
||||
Reference in New Issue
Block a user