1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[lit] Refine adoption of argparse --version action

The real work for this was already done by serge-sans-paille [1].
Thanks for this!

[1] 1d4849379f71a0f5d73202a291c0b709f7cafbc5
This commit is contained in:
Julian Lettner 2019-10-29 23:06:00 -07:00 committed by Julian Lettner
parent c82de1aba3
commit d66362b987
4 changed files with 15 additions and 16 deletions

View File

@ -5,18 +5,17 @@ import sys
import lit.util
def parse_args():
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(prog='lit')
parser.add_argument('test_paths',
nargs='+',
metavar="TEST_PATH",
help='File or path to include in the test suite')
parser.add_argument("--version",
dest="show_version",
help="Show version and exit",
version="lit " + lit.__version__,
action="version")
parser.add_argument('--version',
action='version',
version='%(prog)s ' + lit.__version__)
parser.add_argument("-j", "--threads", "--workers",
dest="workers",
@ -189,12 +188,15 @@ def parse_args():
return opts
def _positive_int(arg):
return _int(arg, 'positive', lambda i: i > 0)
def _non_negative_int(arg):
return _int(arg, 'non-negative', lambda i: i >= 0)
def _int(arg, kind, pred):
desc = "requires {} integer, but found '{}'"
try:
@ -205,6 +207,7 @@ def _int(arg, kind, pred):
raise _error(desc, kind, arg)
return i
def _case_insensitive_regex(arg):
import re
try:
@ -212,6 +215,7 @@ def _case_insensitive_regex(arg):
except re.error as reason:
raise _error("invalid regular expression: '{}', {}", arg, reason)
def _error(desc, *args):
msg = desc.format(*args)
return argparse.ArgumentTypeError(msg)

View File

@ -20,7 +20,6 @@ import lit.util
def main(builtin_params={}):
opts = lit.cl_arguments.parse_args()
params = create_params(builtin_params, opts.user_params)
is_windows = platform.system() == 'Windows'

View File

@ -1,6 +1,7 @@
# Basic sanity check that usage works.
# Basic sanity check for `--help` and `--version` options.
#
# RUN: %{lit} --help > %t.out
# RUN: FileCheck < %t.out %s
# RUN: %{lit} --help | FileCheck %s --check-prefix=HELP
# RUN: %{lit} --version 2>&1 | FileCheck %s --check-prefix=VERSION
#
# CHECK: usage: lit.py [-h]
# HELP: usage: lit [-h]
# VERSION: lit {{[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9]*}}

View File

@ -1,5 +0,0 @@
# Basic sanity check that --version works.
#
# RUN: %{lit} --version 2>&1 | FileCheck %s
#
# CHECK: lit {{[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9]*}}