mirror of
https://github.com/controllerzz/carbus_lib.git
synced 2026-05-22 19:51:41 +03:00
v0.1.8 fix cli
This commit is contained in:
@@ -181,7 +181,23 @@ async def agent_run(
|
||||
log.info("Agent stopped.")
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async def main_async(
|
||||
port: str,
|
||||
baudrate: int,
|
||||
server: str,
|
||||
serial: str,
|
||||
password: str,
|
||||
) -> None:
|
||||
await agent_run(
|
||||
port=port,
|
||||
baudrate=baudrate,
|
||||
server=server,
|
||||
serial=serial,
|
||||
password=password,
|
||||
)
|
||||
|
||||
|
||||
def cli() -> None:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--port", required=True, help="COM port, e.g. COM6")
|
||||
ap.add_argument("--baudrate", type=int, default=115200)
|
||||
@@ -190,18 +206,22 @@ async def main() -> None:
|
||||
ap.add_argument("--password", required=True, help="shared password for this serial")
|
||||
args = ap.parse_args()
|
||||
|
||||
await agent_run(
|
||||
port=args.port,
|
||||
baudrate=args.baudrate,
|
||||
server=args.server,
|
||||
serial=str(args.serial),
|
||||
password=str(args.password),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
)
|
||||
asyncio.run(main())
|
||||
|
||||
asyncio.run(
|
||||
main_async(
|
||||
port=args.port,
|
||||
baudrate=args.baudrate,
|
||||
server=args.server,
|
||||
serial=str(args.serial),
|
||||
password=str(args.password),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
@@ -232,6 +233,18 @@ async def main(host: str = "0.0.0.0", port: int = 9000) -> None:
|
||||
await srv.serve_forever()
|
||||
|
||||
|
||||
def cli() -> None:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--host", default="0.0.0.0")
|
||||
ap.add_argument("--port", type=int, default=9000)
|
||||
args = ap.parse_args()
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
)
|
||||
asyncio.run(main(host=args.host, port=args.port))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s")
|
||||
asyncio.run(main())
|
||||
cli()
|
||||
|
||||
Reference in New Issue
Block a user