Skip to content

Commit dc977a8

Browse files
committed
Update CLI to have -y option to skip confirmation before committing
1 parent 5a9fe6e commit dc977a8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

aicodebot/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ def setup_environment():
3838
api_key = click.prompt("Please enter your OpenAI API key")
3939

4040
# Copy .env.template to .env and insert the API key
41-
with Path.open(Path(__file__).parent / ".aicodebot.template", "r") as template, Path.open(
42-
config_file, "w"
43-
) as env:
41+
template_file = Path(__file__).parent / ".aicodebot.template"
42+
with Path.open(template_file, "r") as template, Path.open(config_file, "w") as env:
4443
for line in template:
4544
if line.startswith("OPENAI_API_KEY="):
4645
env.write(f"OPENAI_API_KEY={api_key}\n")
@@ -63,7 +62,8 @@ def cli():
6362
@cli.command()
6463
@click.option("-v", "--verbose", count=True)
6564
@click.option("-t", "--max-tokens", type=int, default=250)
66-
def commit(verbose, max_tokens):
65+
@click.option("-y", "--yes", is_flag=True, default=False, help="Don't ask for confirmation before committing.")
66+
def commit(verbose, max_tokens, yes):
6767
"""Generate a git commit message based on the diff, and then commit the changes after you approve."""
6868
setup_environment()
6969

@@ -110,7 +110,7 @@ def commit(verbose, max_tokens):
110110
subprocess.call([editor, temp_file_name]) # noqa: S603
111111

112112
# Ask the user if they want to commit the changes
113-
if click.confirm("Do you want to commit the changes?"):
113+
if yes or click.confirm("Do you want to commit the changes?"):
114114
# Commit the changes using the temporary file for the commit message
115115
exec_and_get_output(["git", "commit", "-a", "-F", temp_file_name])
116116

0 commit comments

Comments
 (0)