scripts: Fixed conflicting -C/--compare vs -C/--context errors
Just by hiding -C/--context, -W/--width, --color from argparse unless a related flag (-h/--help, -A/--annotate, etc) is found in sys.argv. This is the same trick we use in test.py/bench.py/perf.py. --- In other news my litmus test that the scripts work was broken. This does _not_ error if a script errors: $ for f in scripts/*.py ; do $f --help ; done An alternative that works is piping stdout to /dev/null, Python's exceptions go to stderr by default: $ for f in scripts/*.py ; do $f --help >/dev/null ; done
This commit is contained in:
+29
-17
@@ -1644,10 +1644,14 @@ def main(**args):
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
import sys
|
||||
import re
|
||||
argparse.ArgumentParser._handle_conflict_ignore = lambda *_: None
|
||||
argparse._ArgumentGroup._handle_conflict_ignore = lambda *_: None
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Aggregate and report call-stack propagated "
|
||||
"block-device operations from trace output.",
|
||||
allow_abbrev=False)
|
||||
allow_abbrev=False,
|
||||
conflict_handler='ignore')
|
||||
class AppendPath(argparse.Action):
|
||||
def __call__(self, parser, namespace, value, option):
|
||||
if getattr(namespace, 'paths', None) is None:
|
||||
@@ -1887,22 +1891,30 @@ if __name__ == "__main__":
|
||||
help="Show lines with erases above this threshold as a percent "
|
||||
"of all lines. Defaults to "
|
||||
"%s." % ','.join(str(t) for t in THRESHOLD))
|
||||
parser.add_argument(
|
||||
'-C', '--context',
|
||||
type=lambda x: int(x, 0),
|
||||
default=3,
|
||||
help="Show n additional lines of context. Defaults to 3.")
|
||||
parser.add_argument(
|
||||
'-W', '--width',
|
||||
type=lambda x: int(x, 0),
|
||||
default=80,
|
||||
help="Assume source is styled with this many columns. Defaults "
|
||||
"to 80.")
|
||||
parser.add_argument(
|
||||
'--color',
|
||||
choices=['never', 'always', 'auto'],
|
||||
default='auto',
|
||||
help="When to use terminal colors. Defaults to 'auto'.")
|
||||
if any(re.fullmatch(
|
||||
'-[^-]*[hAT].*'
|
||||
'|--help'
|
||||
'|--annotate'
|
||||
'|--threshold'
|
||||
'|--read-threshold'
|
||||
'|--prog-threshold'
|
||||
'|--erase-threshold', a) for a in sys.argv):
|
||||
parser.add_argument(
|
||||
'-C', '--context',
|
||||
type=lambda x: int(x, 0),
|
||||
default=3,
|
||||
help="Show n additional lines of context. Defaults to 3.")
|
||||
parser.add_argument(
|
||||
'-W', '--width',
|
||||
type=lambda x: int(x, 0),
|
||||
default=80,
|
||||
help="Assume source is styled with this many columns. "
|
||||
"Defaults to 80.")
|
||||
parser.add_argument(
|
||||
'--color',
|
||||
choices=['never', 'always', 'auto'],
|
||||
default='auto',
|
||||
help="When to use terminal colors. Defaults to 'auto'.")
|
||||
parser.add_argument(
|
||||
'-j', '--jobs',
|
||||
nargs='?',
|
||||
|
||||
Reference in New Issue
Block a user