|
6 | 6 | import subprocess |
7 | 7 | import tempfile |
8 | 8 | from pathlib import Path |
9 | | -from typing import Union, cast |
| 9 | +from typing import TypedDict |
10 | 10 |
|
11 | 11 | import questionary |
12 | 12 |
|
|
28 | 28 | from commitizen.git import smart_open |
29 | 29 |
|
30 | 30 |
|
| 31 | +class CommitArgs(TypedDict, total=False): |
| 32 | + all: bool |
| 33 | + dry_run: bool |
| 34 | + edit: bool |
| 35 | + extra_cli_args: str |
| 36 | + message_length_limit: int |
| 37 | + no_retry: bool |
| 38 | + signoff: bool |
| 39 | + write_message_to_file: Path | None |
| 40 | + retry: bool |
| 41 | + |
| 42 | + |
31 | 43 | class Commit: |
32 | 44 | """Show prompt for the user to create a guided commit.""" |
33 | 45 |
|
34 | | - def __init__(self, config: BaseConfig, arguments: dict) -> None: |
| 46 | + def __init__(self, config: BaseConfig, arguments: CommitArgs) -> None: |
35 | 47 | if not git.is_git_project(): |
36 | 48 | raise NotAGitProjectError() |
37 | 49 |
|
@@ -69,7 +81,7 @@ def _prompt_commit_questions(self) -> str: |
69 | 81 |
|
70 | 82 | message = cz.message(answers) |
71 | 83 | message_len = len(message.partition("\n")[0].strip()) |
72 | | - message_length_limit: int = self.arguments.get("message_length_limit", 0) |
| 84 | + message_length_limit = self.arguments.get("message_length_limit", 0) |
73 | 85 | if 0 < message_length_limit < message_len: |
74 | 86 | raise CommitMessageLengthExceededError( |
75 | 87 | f"Length of commit message exceeds limit ({message_len}/{message_length_limit})" |
@@ -108,12 +120,10 @@ def _get_message(self) -> str: |
108 | 120 | return self._prompt_commit_questions() |
109 | 121 |
|
110 | 122 | def __call__(self) -> None: |
111 | | - extra_args = cast(str, self.arguments.get("extra_cli_args", "")) |
112 | | - dry_run = cast(bool, self.arguments.get("dry_run")) |
113 | | - write_message_to_file = cast( |
114 | | - Union[Path, None], self.arguments.get("write_message_to_file") |
115 | | - ) |
116 | | - signoff = cast(bool, self.arguments.get("signoff")) |
| 123 | + extra_args = self.arguments.get("extra_cli_args", "") |
| 124 | + dry_run = bool(self.arguments.get("dry_run")) |
| 125 | + write_message_to_file = self.arguments.get("write_message_to_file") |
| 126 | + signoff = bool(self.arguments.get("signoff")) |
117 | 127 |
|
118 | 128 | if self.arguments.get("all"): |
119 | 129 | git.add("-u") |
|
0 commit comments