Skip to content

Commit 993a8e3

Browse files
committed
refactor(cli.py): add type hints
1 parent c0220cd commit 993a8e3

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

commitizen/cli.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from functools import partial
99
from pathlib import Path
1010
from types import TracebackType
11-
from typing import Any
11+
from typing import TYPE_CHECKING, Any, cast
1212

1313
import argcomplete
1414
from decli import cli
@@ -596,8 +596,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
596596
return no_raise_codes
597597

598598

599+
if TYPE_CHECKING:
600+
601+
class Args(argparse.Namespace):
602+
config: str | None = None
603+
debug: bool = False
604+
name: str | None = None
605+
no_raise: str | None = None
606+
report: bool = False
607+
project: bool = False
608+
commitizen: bool = False
609+
verbose: bool = False
610+
func: type[
611+
commands.Init # init
612+
| commands.Commit # commit (c)
613+
| commands.ListCz # ls
614+
| commands.Example # example
615+
| commands.Info # info
616+
| commands.Schema # schema
617+
| commands.Bump # bump
618+
| commands.Changelog # changelog (ch)
619+
| commands.Check # check
620+
| commands.Version # version
621+
]
622+
623+
599624
def main():
600-
parser = cli(data)
625+
parser: argparse.ArgumentParser = cli(data)
601626
argcomplete.autocomplete(parser)
602627
# Show help if no arg provided
603628
if len(sys.argv) == 1:
@@ -611,7 +636,7 @@ def main():
611636
# https://github.com/commitizen-tools/commitizen/issues/429
612637
# argparse raises TypeError when non exist command is provided on Python < 3.9
613638
# but raise SystemExit with exit code == 2 on Python 3.9
614-
if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2):
639+
if isinstance(e, TypeError) or e.code == 2:
615640
raise NoCommandFoundError()
616641
raise e
617642

@@ -638,6 +663,7 @@ def main():
638663
arguments["extra_cli_args"] = extra_args
639664

640665
conf = config.read_cfg(args.config)
666+
args = cast("Args", args)
641667
if args.name:
642668
conf.update({"name": args.name})
643669
elif not conf.path:

0 commit comments

Comments
 (0)