# Licensed under a 3-clause BSD style license - see LICENSE.rstimportosimportsysfrom.importcommands,utilfrom.consoleimportlog
[docs]defmain():parser,subparsers=commands.make_argparser()args=parser.parse_args()ifnothasattr(args,'func'):parser.print_help()sys.exit(1)log.enable(args.verbose)# Use the path to the config file as the cwd for the remainder of# the run.# If using the default path, stay in the same dir.ifargs.config:os.chdir(os.path.dirname(os.path.abspath(args.config)))try:result=args.func(args)exceptutil.UserErrorase:log.error(str(e))sys.exit(1)finally:log.flush()ifresultisNone:result=0sys.exit(result)