Skip to content

Commit

Permalink
Exit command line when no ip addr is passed
Browse files Browse the repository at this point in the history
When an IP address is required, the command line now exits with status 1
if none is specified.
  • Loading branch information
jfroy committed Aug 23, 2023
1 parent 77ed6a9 commit 1859eb9
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions aiobafi6/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import difflib
import ipaddress
import logging.config
import sys
import typing as t

from google.protobuf import text_format
Expand Down Expand Up @@ -211,25 +212,32 @@ async def set_property(ip_addr: str, prop: str, value: int):
setattr(dev, prop, int(value))


async def discover():
"""async discover"""
aiozc = AsyncZeroconf(ip_version=IPVersion.V4Only)
_ = ServiceBrowser(
aiozc.zeroconf, lambda services: print(f"== Discover ==\n{services}")
)
while True:
await asyncio.sleep(1)


async def async_main():
"""async_main"""
args = ARGS.parse_args()
logging.config.dictConfig(LOGGING)
ip_addr = None
if args.ip_addr is not None:
try:
ip_addr = ipaddress.ip_address(args.ip_addr)
except ValueError:
print(f"invalid address: {args.ip_addr}")
return
if args.discover:
aiozc = AsyncZeroconf(ip_version=IPVersion.V4Only)
_ = ServiceBrowser(
aiozc.zeroconf, lambda services: print(f"== Discover ==\n{services}")
)
while True:
await asyncio.sleep(1)
elif args.property is not None:
await discover()
return
if args.ip_addr is None:
print("must provide an ip address")
sys.exit(1)
try:
ip_addr = ipaddress.ip_address(args.ip_addr)
except ValueError:
print(f"invalid address: {args.ip_addr}")
sys.exit(1)
if args.property is not None:
if args.value is None:
raise RuntimeError("must specify property value")
if args.direct:
Expand Down

0 comments on commit 1859eb9

Please sign in to comment.