def main(args=None):
lgr.log(5, "Starting main(%r)", args)
# PYTHON_ARGCOMPLETE_OK
parser = setup_parser()
try:
import argcomplete
argcomplete.autocomplete(parser)
except ImportError:
pass
# parse cmd args
cmdlineargs = parser.parse_args(args)
if not cmdlineargs.change_path is None:
for path in cmdlineargs.change_path:
chpwd(path)
if not hasattr(cmdlineargs, 'func'):
lgr.info("No command given, returning")
return
ret = None
if cmdlineargs.common_debug or cmdlineargs.common_idebug:
# so we could see/stop clearly at the point of failure
setup_exceptionhook(ipython=cmdlineargs.common_idebug)
ret = cmdlineargs.func(cmdlineargs)
else:
# otherwise - guard and only log the summary. Postmortem is not
# as convenient if being caught in this ultimate except
try:
ret = cmdlineargs.func(cmdlineargs)
except InsufficientArgumentsError as exc:
# if the func reports inappropriate usage, give help output
lgr.error('%s (%s)' % (exc_str(exc), exc.__class__.__name__))
cmdlineargs.subparser.print_usage()
sys.exit(1)
except MissingConfigFileError as exc:
# TODO: ConfigManager is not finding files in the default locations.
message = """
ERROR: Unable to locate the niceman.cfg file.
You may either specify one using the --config parameter or place one in the
one of following locations:
1. '/etc/niceman/niceman.cfg'
2. 'niceman/config' in all directories defined by $XDG_CONFIG_DIRS
(by default: /etc/xdg/)
3. 'niceman.cfg' in $XDG_CONFIG_HOME (by default: ~/.config/)
4. 'niceman.cfg' in the current directory
"""
# print(message)
lgr.error('%s (%s)' % (exc_str(exc), exc.__class__.__name__))
sys.exit(1)
except Exception as exc:
# print('%s (%s)' % (exc_str(exc), exc.__class__.__name__))
lgr.error('%s (%s)' % (exc_str(exc), exc.__class__.__name__))
sys.exit(1)
if hasattr(cmdlineargs, 'result_renderer'):
cmdlineargs.result_renderer(ret)
评论列表
文章目录