Skip to content

Commit 8a4a008

Browse files
committed
✨ feat(cli): set process title on startup
1 parent 1d12500 commit 8a4a008

4 files changed

Lines changed: 100 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies = [
1212
"questionary>=2.0.1",
1313
"beautifulsoup4>=4.13.3",
1414
"click>=8.0.0",
15+
"setproctitle>=1.3.7",
1516
]
1617
readme = { content-type = "text/markdown", file = "README.md" }
1718
requires-python = ">= 3.11"

tests/unit/test_cli.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import threading
55
from click.testing import CliRunner
66

7-
from tgit.cli import app, set_terminal_title, version_callback
7+
from tgit.cli import app, set_process_title, set_terminal_title, version_callback
88

99

1010
class TestCLI:
@@ -53,15 +53,17 @@ def test_version_callback_false(self, mock_print, mock_version):
5353
mock_ctx.exit.assert_not_called()
5454

5555
@patch("tgit.cli.threading.Thread")
56+
@patch("tgit.cli.set_process_title")
5657
@patch("tgit.cli.set_terminal_title")
57-
def test_app_starts_openai_import_thread(self, mock_set_terminal_title, mock_thread):
58+
def test_app_starts_openai_import_thread(self, mock_set_terminal_title, mock_set_process_title, mock_thread):
5859
"""Test that app starts a thread for OpenAI import"""
5960
mock_thread_instance = MagicMock()
6061
mock_thread.return_value = mock_thread_instance
6162

6263
# Directly call the app function to test the callback
6364
app.callback()
6465

66+
mock_set_process_title.assert_called_once_with("tgit")
6567
mock_set_terminal_title.assert_called_once_with("tgit")
6668
# The app should run the callback and start the thread
6769
mock_thread.assert_called_once()
@@ -88,6 +90,20 @@ def test_app_callback_registration(self):
8890
assert isinstance(app, click.Group)
8991
# Verify the app exists and is configured correctly
9092

93+
@patch("tgit.cli.setproctitle_module.setproctitle")
94+
def test_set_process_title_updates_process_name(self, mock_setproctitle):
95+
"""Test process title is updated when support is available."""
96+
set_process_title("tgit")
97+
98+
mock_setproctitle.assert_called_once_with("tgit")
99+
100+
@patch("tgit.cli.setproctitle_module.setproctitle", side_effect=RuntimeError("boom"))
101+
def test_set_process_title_ignores_errors(self, mock_setproctitle):
102+
"""Test process title errors do not break CLI startup."""
103+
set_process_title("tgit")
104+
105+
mock_setproctitle.assert_called_once_with("tgit")
106+
91107
@patch("tgit.cli.sys.stdout.flush")
92108
@patch("tgit.cli.sys.stdout.write")
93109
@patch("tgit.cli.sys.stdout.isatty", return_value=True)

tgit/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import threading
55

66
import click
7+
import setproctitle as setproctitle_module
78

89
from tgit.add import add
910
from tgit.changelog import changelog
@@ -13,6 +14,11 @@
1314
from tgit.version import version
1415

1516

17+
def set_process_title(title: str) -> None:
18+
with contextlib.suppress(Exception):
19+
setproctitle_module.setproctitle(title)
20+
21+
1622
def set_terminal_title(title: str) -> None:
1723
if not sys.stdout.isatty():
1824
return
@@ -42,6 +48,7 @@ def version_callback(ctx: click.Context, _param: click.Parameter, value: bool) -
4248
help="Show version",
4349
)
4450
def app() -> None:
51+
set_process_title("tgit")
4552
set_terminal_title("tgit")
4653

4754
def import_openai() -> None:

0 commit comments

Comments
 (0)