Skip to content

Commit 8f261f6

Browse files
committed
✨ feat(settings): add interactive settings command and improve config options
1 parent 83c8a7e commit 8f261f6

8 files changed

Lines changed: 361 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.19.1
2+
3+
[v0.19.0...v0.19.1](https://github.com/Jannchie/tgit/compare/v0.19.0...v0.19.1)
4+
15
## v0.19.0
26

37
[v0.18.0...v0.19.0](https://github.com/Jannchie/tgit/compare/v0.18.0...v0.19.0)

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,6 @@ No specific test framework is configured. Check if tests exist before adding new
100100

101101
### Dependencies
102102

103-
- Core: rich, pyyaml, inquirer, gitpython, openai, jinja2, beautifulsoup4
103+
- Core: rich, pyyaml, questionary, gitpython, openai, jinja2, beautifulsoup4
104104
- Build: hatchling via uv
105105
- Code quality: ruff (configured for line length 140, extensive rule set)

tgit/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
import importlib.metadata
33
import threading
44

5-
import rich
6-
import rich.traceback
75
import typer
86

97
from tgit.add import add
108
from tgit.changelog import changelog
119
from tgit.commit import commit
1210
from tgit.config import config
11+
from tgit.settings_command import settings
1312
from tgit.utils import console
1413
from tgit.version import version
1514

16-
rich.traceback.install()
17-
1815
app = typer.Typer(
1916
name="tgit",
2017
help="TGIT cli",
@@ -27,6 +24,7 @@
2724
app.command("changelog", help="generate changelogs")(changelog)
2825
app.command("add", help="same as git add")(add)
2926
app.command("config", help="edit settings")(config)
27+
app.command("settings", help="interactive settings configuration")(settings)
3028

3129

3230
def version_callback(*, value: bool) -> None:

tgit/commit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ def get_ai_command(specified_type: str | None = None) -> str | None:
223223
print(e)
224224
return None
225225

226-
# 如果用户指定了类型,则使用用户指定的类型
227-
commit_type = specified_type or resp.type
226+
# 如果用户指定了类型,则使用用户指定的类型,否则使用 AI 生成的类型
227+
commit_type = specified_type if specified_type is not None else resp.type
228228

229229
return get_commit_command(
230230
commit_type,

tgit/config.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
import typer
22
from rich import print
33

4+
from .interactive_settings import interactive_settings
45
from .settings import set_global_settings
56

67

78
def config(
8-
key: str = typer.Argument(..., help="setting key"),
9-
value: str = typer.Argument(..., help="setting value"),
9+
key: str = typer.Argument(None, help="setting key"),
10+
value: str = typer.Argument(None, help="setting value"),
11+
*,
12+
interactive: bool = typer.Option(False, "--interactive", "-i", help="Interactive configuration mode"),
1013
) -> None:
11-
available_keys = ["apiKey", "apiUrl", "model"]
14+
if interactive or (key is None and value is None):
15+
interactive_settings()
16+
return
17+
18+
if key is None or value is None:
19+
print("Both key and value are required when not using interactive mode")
20+
print("Use --interactive or -i for interactive configuration")
21+
raise typer.Exit(1)
22+
23+
available_keys = ["apiKey", "apiUrl", "model", "show_command", "skip_confirm"]
1224

1325
if key not in available_keys:
14-
print(f"Key {key} is not valid")
26+
print(f"Key {key} is not valid. Available keys: {', '.join(available_keys)}")
1527
raise typer.Exit(1)
1628

29+
# Convert boolean strings
30+
if key in ["show_command", "skip_confirm"]:
31+
if value.lower() in ["true", "1", "yes", "on"]:
32+
value = True
33+
elif value.lower() in ["false", "0", "no", "off"]:
34+
value = False
35+
else:
36+
print(f"Invalid boolean value for {key}. Use true/false, 1/0, yes/no, or on/off")
37+
raise typer.Exit(1)
38+
1739
set_global_settings(key, value)
40+
print(f"[green]Setting {key} updated successfully![/green]")

0 commit comments

Comments
 (0)