fix argument parsing for test suite

This commit is contained in:
Jonathan Wren 2020-05-23 13:28:15 -07:00
parent b5c671c055
commit 2522582b5d
2 changed files with 14 additions and 6 deletions

View file

@ -166,9 +166,11 @@ def run(context, command, cache_dir=None):
cache_dir = os.path.join("features", "cache", cache_dir) cache_dir = os.path.join("features", "cache", cache_dir)
command = command.format(cache_dir=cache_dir) command = command.format(cache_dir=cache_dir)
args = ushlex(command)[1:] args = ushlex(command)
try: try:
cli.run(args or None) with patch('sys.argv', args):
cli.run(args[1:])
context.exit_status = 0 context.exit_status = 0
except SystemExit as e: except SystemExit as e:
context.exit_status = e.code context.exit_status = e.code

View file

@ -194,11 +194,14 @@ def parse_args(args=None):
help="Opens an interactive interface for deleting entries.", help="Opens an interactive interface for deleting entries.",
) )
if not args:
args = []
# Handle '-123' as a shortcut for '-n 123' # Handle '-123' as a shortcut for '-n 123'
num = re.compile(r"^-(\d+)$") num = re.compile(r"^-(\d+)$")
if args is None: args = [num.sub(r"-n \1", arg) for arg in args]
args = []
return parser.parse_args([num.sub(r"-n \1", a) for a in args]) return parser.parse_args(args)
def guess_mode(args, config): def guess_mode(args, config):
@ -300,6 +303,9 @@ def configure_logger(debug=False):
def run(manual_args=None): def run(manual_args=None):
if manual_args is None:
manual_args = sys.argv[1:]
args = parse_args(manual_args) args = parse_args(manual_args)
configure_logger(args.debug) configure_logger(args.debug)