def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise ExpectedExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except TypeError: raise NoCommandFoundError() if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.debug: logging.getLogger("commitizen").setLevel(logging.DEBUG) sys.excepthook = commitizen_debug_excepthook args.func(conf, vars(args))()
def main(): conf = config.read_cfg() parser = cli(data) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise ExpectedExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except TypeError: raise NoCommandFoundError() if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.version: warnings.warn( ("'cz --version' will be deprecated in next major version. " "Please use 'cz version' command from your scripts"), category=DeprecationWarning, ) args.func = commands.Version if args.debug: logging.getLogger("commitizen").setLevel(logging.DEBUG) sys.excepthook = commitizen_debug_excepthook # TODO: This try block can be removed after command is required in 2.0 # Handle the case that argument is given, but no command is provided try: args.func(conf, vars(args))() except AttributeError: raise NoCommandFoundError()
def main(): conf = config.read_cfg() parser = cli(data) argcomplete.autocomplete(parser) # Show help if no arg provided if len(sys.argv) == 1: parser.print_help(sys.stderr) raise ExpectedExit() # This is for the command required constraint in 2.0 try: args = parser.parse_args() except (TypeError, SystemExit) as e: # https://github.com/commitizen-tools/commitizen/issues/429 # argparse raises TypeError when non exist command is provided on Python < 3.9 # but raise SystemExit with exit code == 2 on Python 3.9 if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2): raise NoCommandFoundError() raise e if args.name: conf.update({"name": args.name}) elif not args.name and not conf.path: conf.update({"name": "cz_conventional_commits"}) if args.debug: logging.getLogger("commitizen").setLevel(logging.DEBUG) sys.excepthook = commitizen_debug_excepthook elif args.no_raise: no_raise_exit_codes = parse_no_raise(args.no_raise) no_raise_debug_excepthook = partial(commitizen_excepthook, no_raise=no_raise_exit_codes) sys.excepthook = no_raise_debug_excepthook args.func(conf, vars(args))()