Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8a76b40

Browse files
committed
refactor(cli.py): add type hints
1 parent a3919c9 commit 8a76b40

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
@@ -597,8 +597,33 @@ def parse_no_raise(comma_separated_no_raise: str) -> list[int]:
597597
return no_raise_codes
598598

599599

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

@@ -639,6 +664,7 @@ def main():
639664
arguments["extra_cli_args"] = extra_args
640665

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

0 commit comments

Comments
 (0)