Skip to content

Commit

Permalink
Merge pull request #3 from KnowKit/feature/print-command
Browse files Browse the repository at this point in the history
✨: add new option print
  • Loading branch information
arrrrrmin authored Feb 24, 2022
2 parents 7e03ca6 + cd3156a commit 137025a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions convmoji/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
--co-authored-by '<User user@no-reply> '\
--co-authored-by '<User2 user2@no-reply>'",
"debug": "Debug mode (does not execute commit)",
"print": "Print the commit message (does not execute commit)",
"info": "Prompt convmoji info (does not execute commit)",
"version": "Prompt convmoji version (does not execute commit)",
}
Expand Down Expand Up @@ -96,6 +97,7 @@ def commit(
help=helpers["co-authored-by"],
),
debug: bool = typer.Option(False, "--debug", help=helpers["debug"]),
print_message: bool = typer.Option(False, "--print", help=helpers["print"]),
info: typing.Optional[bool] = typer.Option( # noqa: U100
None,
"--info",
Expand Down Expand Up @@ -124,6 +126,8 @@ def commit(
)
if debug:
typer.echo(repr(cmd))
elif print_message:
typer.echo(cmd.message_formatter())
else:
os.system(repr(cmd)) # pragma: no cover

Expand Down
19 changes: 11 additions & 8 deletions convmoji/commit_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CommitCmd(BaseModel):
no_verify: typing.Optional[bool]
co_authored_by: typing.Optional[typing.List[str]]

def _message_formatter(self):
def message_formatter(self):
message = self.description
if self.body:
message += f"\n\n{self.body}"
Expand All @@ -62,15 +62,18 @@ def _message_formatter(self):
[f"Co-authored-by: {author}" for author in self.co_authored_by]
),
)
return message
if self.breaking_changes:
self.type = f"{self.type}‼️"

if self.scope == "":
return f"{self.type}: {message}"

return f"{self.type}({self.scope}): {message}"

def __repr__(self):
optional_args = ""
optional_args += "--amend " if self.amend else ""
optional_args += "--no-verify " if self.no_verify else ""
if self.breaking_changes:
self.type = f"{self.type}‼️"
message = self._message_formatter()
if self.scope == "":
return f'{commit_cmd_base} "{self.type}: {message}" {optional_args}'
return f'{commit_cmd_base} "{self.type}({self.scope}): {message}" {optional_args}'

message = self.message_formatter()
return f'{commit_cmd_base} "{message}" {optional_args}'
6 changes: 6 additions & 0 deletions tests/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,9 @@ def test_app_commit_info_007():
def test_app_commit_version_008():
result = invoke_app_commit("--version")
assert f"{__name__} {__version__}" in result.stdout

def test_print_message(default_description: str):
result = invoke_app_commit(default_description, "--print")
assert f"✨: {default_description}\n\n" == result.stdout


0 comments on commit 137025a

Please sign in to comment.