Commit 12872262 authored by Alexandre's avatar Alexandre
Browse files

Split options in usage and do not display usage on error

parent 402c2a95
......@@ -114,43 +114,46 @@ def usage(msg=None):
print("Usage: %s [options] url-or-servername [domain-name [DNS type]]" % sys.argv[0], file=sys.stderr)
print("""Options
-t --dot Use DoT (by default use DoH)
-P --post --POST Use HTTP POST method for all transfers (DoH only)
-e --head --HEAD Use HTTP HEAD method for all transfers (DoH only)
-k --insecure Do not check the certificate
-4 --v4only Force IPv4 resolution of url-or-servername
-6 --v6only Force IPv6 resolution of url-or-servername
-v --verbose Make the program more talkative
--debug Make the program even more talkative than -v
-r --repeat <N> Perform N times the query. If used with -f, read up to
<N> rows of the <file>.
<N> lines of the <file>
-d --delay <T> Time to wait in seconds between each synchronous
request (only with --repeat)
-f --file <file> Read domain names from <file>, one per row with an
optional DNS type
--check Perform a set of predefined tests.
optional DNS type. Read the first line only, use
--repeat N to read up to N lines of the file
--check Perform a set of predefined tests
--mandatory-level <level>
Define the <level> of test to perform (only with
--check)
Available <level> : legal, necessary, nicetohave
--multistreams Use HTTP/2 streams, needs an input file with -f
(DoH only)
--sync Process received queries synchronously (only with
--multistreams)
--no-display-results
Disable output of DNS response (only with
--multistreams)
--time Display the time elapsed for the query (only with
--multistreams)
Disable output of DNS response
--dnssec Request DNSSEC data (signatures)
--noedns Disable EDNS, default is to indicate EDNS support
--ecs Send ECS to authoritative servers, default is to
refuse it
--key <key> Authenticate a DoT resolver with its public <key> in
base64 (DoT only)
--nosni Do not perform SNI (DoT only)
-V --vhost <vhost> Use a specific virtual host
-k --insecure Do not check the certificate
-4 --v4only Force IPv4 resolution of url-or-servername
-6 --v6only Force IPv6 resolution of url-or-servername
-v --verbose Make the program more talkative
--debug Make the program even more talkative than -v
-h --help Print this message
DoH only options:
-P --post --POST Use HTTP POST method for all the transfers
-e --head --HEAD Use HTTP HEAD method for all the transfers
--multistreams Use HTTP/2 streams, needs an input file with -f
--sync Process received queries synchronously (only with
--multistreams)
--time Display the time elapsed for the query (only with
--multistreams)
DoT only options:
--key <key> Authenticate a DoT resolver with its public <key> in
base64
--nosni Do not perform SNI
url-or-servername The URL or domain name of the DoT/DoH server
domain-name The domain name to resolve, not required if -f is
provided
......@@ -1115,57 +1118,57 @@ if not monitoring:
else:
error("Unknown option %s" % option)
except (getopt.error, ValueError) as reason:
usage(reason)
error(reason)
sys.exit(1)
if delay is not None and multistreams:
error("--delay makes no sense with multistreams")
if tests <= 1 and delay is not None:
error("--delay makes no sense if there is no repetition")
if not dot and pipelining:
usage("Pipelining is only accepted for DoT")
error("Pipelining is only accepted for DoT")
sys.exit(1)
if dot and (post or head):
usage("POST or HEAD makes non sense for DoT")
error("POST or HEAD makes non sense for DoT")
sys.exit(1)
if post and head:
usage("POST or HEAD but not both")
error("POST or HEAD but not both")
sys.exit(1)
if pipelining and ifile is None:
usage("Pipelining requires an input file")
error("Pipelining requires an input file")
sys.exit(1)
if check and multistreams:
usage("--check and --multistreams are not compatible")
error("--check and --multistreams are not compatible")
sys.exit(1)
if dot and multistreams:
usage("Multi-streams makes no sense for DoT")
error("Multi-streams makes no sense for DoT")
sys.exit(1)
if multistreams and ifile is None:
usage("Multi-streams requires an input file")
error("Multi-streams requires an input file")
sys.exit(1)
if sync and not multistreams:
usage("--sync cannot be used without --multistreams")
error("--sync cannot be used without --multistreams")
sys.exit(1)
if show_time and dot:
usage("--time cannot be used with --dot")
error("--time cannot be used with --dot")
sys.exit(1)
if not edns and not no_ecs:
usage("ECS requires EDNS")
error("ECS requires EDNS")
sys.exit(1)
if mandatory_level is not None and \
mandatory_level not in mandatory_levels.keys():
usage("Unknown mandatory level \"%s\"" % mandatory_level)
error("Unknown mandatory level \"%s\"" % mandatory_level)
sys.exit(1)
if mandatory_level is not None and not check:
usage("--mandatory-level only makes sense with --check")
error("--mandatory-level only makes sense with --check")
sys.exit(1)
if mandatory_level is None:
mandatory_level = "necessary"
mandatory_level = mandatory_levels[mandatory_level]
if ifile is None and (len(args) != 2 and len(args) != 3):
usage("Wrong number of arguments")
error("Wrong number of arguments")
sys.exit(1)
if ifile is not None and len(args) != 1:
usage("Wrong number of arguments (if --file is used, do not indicate the domain name)")
error("Wrong number of arguments (if --file is used, do not indicate the domain name)")
sys.exit(1)
url = args[0]
if ifile is None:
......
......@@ -26,7 +26,7 @@ tests:
args:
- '--zzz'
retcode: 1
partstderr: 'url-or-servername [domain-name [DNS type]]'
partstderr: 'option --zzz not recognized'
stdout: ''
- exe: './homer.py'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment