From ff18f26104df5994cf135fd28ffaad35b0d9449c Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Sat, 17 Feb 2024 13:50:49 +0100 Subject: [PATCH] Support long form arguments --- README.rst | 18 ++++++++++-------- wakeonlan/__init__.py | 18 +++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index 2de9053..910199e 100644 --- a/README.rst +++ b/README.rst @@ -85,18 +85,20 @@ As a standalone script :: - usage: wakeonlan [-h] [-i ip] [-p port] [-n interface] mac address [mac address ...] + usage: wakeonlan [-h] [-6] [-i IP] [-p PORT] [-n INTERFACE] mac address [mac address ...] Wake one or more computers using the wake on lan protocol. positional arguments: - mac address The mac addresses of the computers you are trying to wake. - - optional arguments: - -h, --help show this help message and exit - -i ip The ip address of the host to send the magic packet to. (default 255.255.255.255) - -p port The port of the host to send the magic packet to. (default 9) - -n interface The ip address of the network adapter to route the magic packet through. (optional) + mac address The mac addresses of the computers you are trying to wake. + + options: + -h, --help show this help message and exit + -6, --ipv6 To indicate if ipv6 should be used by default instead of ipv4. (default: False) + -i IP, --ip IP The ip address of the host to send the magic packet to. (default: 255.255.255.255) + -p PORT, --port PORT The port of the host to send the magic packet to. (default: 9) + -n INTERFACE, --interface INTERFACE + The ip address of the network adapter to route the magic packet through. (default: None) ************ diff --git a/wakeonlan/__init__.py b/wakeonlan/__init__.py index 412e064..d8487c4 100755 --- a/wakeonlan/__init__.py +++ b/wakeonlan/__init__.py @@ -102,36 +102,36 @@ def main(argv: typing.Optional[typing.List[str]] = None) -> None: ) parser.add_argument( '-6', - dest='use_ipv6', + '--ipv6', action='store_true', help='To indicate if ipv6 should be used by default instead of ipv4.', ) parser.add_argument( '-i', - metavar='ip', + '--ip', default=BROADCAST_IP, help='The ip address of the host to send the magic packet to.', ) parser.add_argument( '-p', - metavar='port', + '--port', type=int, default=DEFAULT_PORT, help='The port of the host to send the magic packet to.', ) parser.add_argument( '-n', - metavar='interface', - default=None, + '--interface', help='The ip address of the network adapter to route the magic packet through.', ) args = parser.parse_args(argv) + print(args) send_magic_packet( *args.macs, - ip_address=args.i, - port=args.p, - interface=args.n, - address_family=socket.AF_INET6 if args.use_ipv6 else None, + ip_address=args.ip, + port=args.port, + interface=args.interface, + address_family=socket.AF_INET6 if args.ipv6 else None, )