# HG changeset patch # User Ludovic Chabant # Date 1431408245 25200 # Node ID d241585412add4e7cd9e7302c04112c502cd4d46 # Parent 44cf6ce62467f08d8a980f0b24ae5bc70340af57 internal: Make it possible to pass `argv` to the main Chef function. This makes it easy to write system tests against the CLI. diff -r 44cf6ce62467 -r d241585412ad piecrust/main.py --- a/piecrust/main.py Sun May 10 23:34:50 2015 -0700 +++ b/piecrust/main.py Mon May 11 22:24:05 2015 -0700 @@ -60,10 +60,10 @@ except ValueError: locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') - argv = sys.argv + argv = sys.argv[1:] pre_args = _pre_parse_chef_args(argv) try: - exit_code = _run_chef(pre_args) + exit_code = _run_chef(pre_args, argv) except Exception as ex: if pre_args.debug: logger.exception(ex) @@ -100,7 +100,7 @@ # related arguments must be parsed first because we want to log everything # from the beginning. res = PreParsedChefArgs() - i = 1 + i = 0 while i < len(argv): arg = argv[i] if arg.startswith('--root='): @@ -166,7 +166,7 @@ return res -def _run_chef(pre_args): +def _run_chef(pre_args, argv): # Setup the app. start_time = time.clock() root = pre_args.root @@ -250,7 +250,7 @@ parser.epilog = epilog.getvalue() # Parse the command line. - result = parser.parse_args() + result = parser.parse_args(argv) logger.debug(format_timed(start_time, 'initialized PieCrust', colored=False))