comparison piecrust/main.py @ 98:5959a117a943

Exit with the proper code.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 08 Sep 2014 00:04:29 -0700
parents 00a9b24ca944
children 8703be118430
comparison
equal deleted inserted replaced
97:00a9b24ca944 98:5959a117a943
52 52
53 def main(): 53 def main():
54 argv = sys.argv 54 argv = sys.argv
55 pre_args = _pre_parse_chef_args(argv) 55 pre_args = _pre_parse_chef_args(argv)
56 try: 56 try:
57 return _run_chef(pre_args) 57 exit_code = _run_chef(pre_args)
58 except Exception as ex: 58 except Exception as ex:
59 if pre_args.debug: 59 if pre_args.debug:
60 logger.exception(ex) 60 logger.exception(ex)
61 else: 61 else:
62 log_friendly_exception(logger, ex) 62 log_friendly_exception(logger, ex)
63 return 1 63 exit_code = 1
64 sys.exit(exit_code)
64 65
65 66
66 class PreParsedChefArgs(object): 67 class PreParsedChefArgs(object):
67 def __init__(self, root=None, cache=True, debug=False, quiet=False, 68 def __init__(self, root=None, cache=True, debug=False, quiet=False,
68 log_file=None, log_debug=False, config_variant=None): 69 log_file=None, log_debug=False, config_variant=None):
199 return 0 200 return 0
200 201
201 # Run the command! 202 # Run the command!
202 ctx = CommandContext(app, parser, result) 203 ctx = CommandContext(app, parser, result)
203 exit_code = result.func(ctx) 204 exit_code = result.func(ctx)
205 if exit_code is None:
206 return 0
207 if not isinstance(exit_code, int):
208 logger.error("Got non-integer exit code: %s" % exit_code)
209 return -1
204 return exit_code 210 return exit_code
205 211