[Git][NTPsec/ntpsec][master] 5 commits: getopt already checks for invalid options or options missing arguments
Eric S. Raymond
gitlab at mg.gitlab.com
Mon Nov 14 20:46:48 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
7073cf83 by Matt Selsky at 2016-11-14T12:20:24-05:00
getopt already checks for invalid options or options missing arguments
..so consolidate our error messages
- - - - -
87a8a864 by Matt Selsky at 2016-11-14T12:30:30-05:00
ntpq's set-debug-level takes integers
- - - - -
da5dd1f8 by Matt Selsky at 2016-11-14T12:51:28-05:00
Make sure ntpq's getopt long options take their arguments
- - - - -
ca8aaf22 by Matt Selsky at 2016-11-14T13:03:07-05:00
Call interpreter.warn() statically since we're in main()
and self doesn't exist
- - - - -
88b527aa by Matt Selsky at 2016-11-14T14:39:03-05:00
Make sure pyntpdig getopt long-options take a value
Also add missing long-option "steplimit"
- - - - -
3 changed files:
- docs/includes/ntpq-body.txt
- ntpdig/pyntpdig
- ntpq/ntpq
Changes:
=====================================
docs/includes/ntpq-body.txt
=====================================
--- a/docs/includes/ntpq-body.txt
+++ b/docs/includes/ntpq-body.txt
@@ -65,7 +65,7 @@ attempt to read interactive format commands from the standard input.
+-d+, +--debug+::
Increase debugging level by 1.
+-D+ num, +--set-debug-level+=num::
- The debug level is set to the following numeric argument.
+ The debug level is set to the following integer argument.
+-h+, +--help+::
Print a usage message summarizing options end exit.
+-i+, +--interactive+::
=====================================
ntpdig/pyntpdig
=====================================
--- a/ntpdig/pyntpdig
+++ b/ntpdig/pyntpdig
@@ -284,14 +284,14 @@ if __name__ == '__main__':
(options, arguments) = getopt.getopt(sys.argv[1:],
"46a:c:dD:g:hjk:l:M:o:p:Sst:wWV",
["ipv4","ipv6",
- "authentication",
- "concurrent",
- "gap", "help", "json",
- "keyfile", "logfile",
- "steplimit",
+ "authentication=",
+ "concurrent=",
+ "gap=", "help", "json",
+ "keyfile=", "logfile=",
+ "samples=", "steplimit=",
"step", "slew",
- "timeout",
- "debug", "set-debug-level",
+ "timeout=",
+ "debug", "set-debug-level=",
"version"])
except getopt.GetoptError as e:
print(e)
=====================================
ntpq/ntpq
=====================================
--- a/ntpq/ntpq
+++ b/ntpq/ntpq
@@ -1490,7 +1490,7 @@ USAGE: ntpq [-46dphinOV] [-c str] [-D lvl] [ host ...]
- may appear multiple times
-d no debug-level Increase output debug message level
- may appear multiple times
- -D Str set-debug-level Set the output debug message level
+ -D Int set-debug-level Set the output debug message level
- may appear multiple times
-h no help Print a usage message.
-p no peers Print a list of the peers
@@ -1511,13 +1511,14 @@ if __name__ == '__main__':
try:
(options, arguments) = getopt.getopt(sys.argv[1:],
"46c:dD:hinpVw",
- ["ipv4","ipv6", "command",
- "debug", "set-debug-level",
+ ["ipv4","ipv6", "command=",
+ "debug", "set-debug-level=",
"help", "interactive", "numeric",
"peers", "version",
"wide"])
except getopt.GetoptError as e:
- print(e)
+ sys.stderr.write("%s\n" % e)
+ sys.stderr.write(usage)
raise SystemExit(1)
progname = sys.argv[0]
@@ -1535,7 +1536,12 @@ if __name__ == '__main__':
interpreter.debug += 1
session.debug += 1
elif switch in ("-D", "--set-debug-level"):
- session.debug = interpreter.debug = int(val)
+ try:
+ session.debug = interpreter.debug = int(val)
+ except ValueError as e:
+ sys.stderr.write("'%s' is not a recognizable number\n" % val)
+ sys.stderr.write(usage)
+ raise SystemExit(1)
elif switch in ("-h", "--help"):
print(usage)
raise SystemExit(0)
@@ -1550,13 +1556,9 @@ if __name__ == '__main__':
raise SystemExit(0)
elif switch in ("-w", "--wide"):
interpreter.wideremote = True
- else:
- self.warn("Unknown command line switch or missing argument.\n")
- self.warn(usage)
- raise SystemExit(1)
if interpreter.interactive and len(interpreter.ccmds) > 0:
- self.warn("%s: invalid option combination.\n" % progname)
+ interpreter.warn("%s: invalid option combination.\n" % progname)
raise SystemExit(1)
if len(arguments) == 0:
@@ -1577,7 +1579,7 @@ if __name__ == '__main__':
try:
if len(interpreter.ccmds) == 0:
if len(interpreter.chosts) > 1:
- self.warn("ntpq can only work interactively on one host.")
+ interpreter.warn("ntpq can only work interactively on one host.\n")
interpreter.chosts = interpreter.chosts[:1]
session.openhost(*interpreter.chosts[0])
interpreter.cmdloop()
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/b98ec8b2d837107b90e5d91970fc5ce84507dd18...88b527aa37c6e2a9a32e619376e27f5b697104fc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20161114/0e419f02/attachment.html>
More information about the vc
mailing list