Allow intermixing of options and arguments
Closed this issue · 0 comments
pklapperich commented
One of the things that's always annoyed me with woof
is that it requires all of the options before the arguments.
Example:
$ woof /tmp/Screenshot_2022-01-13_11-12-40.png
cannot bind to IP address '' port 8080
$ woof /tmp/Screenshot_2022-01-13_11-12-40.png -p 8000
Usage: woof [-i <ip_addr>] [-p <port>] [-c <count>] <file>
woof [-i <ip_addr>] [-p <port>] [-c <count>] [-z|-j|-Z|-u] <dir>
woof [-i <ip_addr>] [-p <port>] [-c <count>] -s
woof [-i <ip_addr>] [-p <port>] [-c <count>] -U
woof <url> ... [Snip]
But this is easily fixed by just calling gnu_getopt()
instead of getopt()
$ git diff
diff --git a/woof b/woof
index 74784af..414deca 100755
--- a/woof
+++ b/woof
@@ -483,7 +483,7 @@ def main ():
defaultmaxdown = maxdown
try:
- options, filenames = getopt.getopt (sys.argv[1:], "hUszjZui:c:p:")
+ options, filenames = getopt.gnu_getopt (sys.argv[1:], "hUszjZui:c:p:")
except getopt.GetoptError as desc:
usage (defaultport, defaultmaxdown, desc)
$ ./woof /tmp/Screenshot_2022-01-13_11-12-40.png
cannot bind to IP address '' port 8080
$ ./woof /tmp/Screenshot_2022-01-13_11-12-40.png -p 8000
Now serving on http://10.0.1.104:8000/Screenshot_2022-01-13_11-12-40.png