def main():
parser = get_parser()
if sys.stdin.isatty():
try:
import argcomplete
except ImportError:
pass
else:
argcomplete.autocomplete(parser)
args = parser.parse_args()
args = vars(args)
args.pop("command")
args.pop("subcommand", None)
func_name = args.pop("func")
func = import_func(func_name)
try:
result, exit_code = func(**args)
except:
if not sys.stdin.isatty():
import traceback
msg = traceback.format_exc()
handle_error(msg)
raise
else:
if result:
# nonzero exit codes for non-interactive commands should be
# logged
if exit_code > 0 and not sys.stdin.isatty() and not sys.stdout.isatty():
handle_error(result)
# otherwise print
else:
print(result)
return exit_code
评论列表
文章目录