renamed io.tool() -> io.tool_output()

This commit is contained in:
Paul Gauthier 2023-05-27 15:17:33 -07:00
parent f6d07d9849
commit cc9b21df06
4 changed files with 35 additions and 35 deletions

View file

@ -76,7 +76,7 @@ class Coder:
if self.repo: if self.repo:
rel_repo_dir = os.path.relpath(self.repo.git_dir, os.getcwd()) rel_repo_dir = os.path.relpath(self.repo.git_dir, os.getcwd())
self.io.tool("Using git repo:", rel_repo_dir) self.io.tool_output("Using git repo:", rel_repo_dir)
else: else:
self.io.tool_error("No suitable git repo, will not automatically commit edits.") self.io.tool_error("No suitable git repo, will not automatically commit edits.")
self.find_common_root() self.find_common_root()
@ -93,7 +93,7 @@ class Coder:
else: else:
self.root = os.getcwd() self.root = os.getcwd()
self.io.tool(f"Common root directory: {self.root}") self.io.tool_output(f"Common root directory: {self.root}")
def set_repo(self, cmd_line_fnames): def set_repo(self, cmd_line_fnames):
if not cmd_line_fnames: if not cmd_line_fnames:
@ -103,7 +103,7 @@ class Coder:
for fname in cmd_line_fnames: for fname in cmd_line_fnames:
fname = Path(fname) fname = Path(fname)
if not fname.exists(): if not fname.exists():
self.io.tool(f"Creating empty file {fname}") self.io.tool_output(f"Creating empty file {fname}")
fname.parent.mkdir(parents=True, exist_ok=True) fname.parent.mkdir(parents=True, exist_ok=True)
fname.touch() fname.touch()
@ -116,7 +116,7 @@ class Coder:
if fname.is_dir(): if fname.is_dir():
continue continue
self.io.tool(f"Added {fname} to the chat") self.io.tool_output(f"Added {fname} to the chat")
fname = fname.resolve() fname = fname.resolve()
self.abs_fnames.add(str(fname)) self.abs_fnames.add(str(fname))
@ -145,18 +145,18 @@ class Coder:
if new_files: if new_files:
rel_repo_dir = os.path.relpath(repo.git_dir, os.getcwd()) rel_repo_dir = os.path.relpath(repo.git_dir, os.getcwd())
self.io.tool(f"Files not tracked in {rel_repo_dir}:") self.io.tool_output(f"Files not tracked in {rel_repo_dir}:")
for fn in new_files: for fn in new_files:
self.io.tool(f" - {fn}") self.io.tool_output(f" - {fn}")
if self.io.confirm_ask("Add them?"): if self.io.confirm_ask("Add them?"):
for relative_fname in new_files: for relative_fname in new_files:
repo.git.add(relative_fname) repo.git.add(relative_fname)
self.io.tool(f"Added {relative_fname} to the git repo") self.io.tool_output(f"Added {relative_fname} to the git repo")
show_files = ", ".join(new_files) show_files = ", ".join(new_files)
commit_message = f"Added new files to the git repo: {show_files}" commit_message = f"Added new files to the git repo: {show_files}"
repo.git.commit("-m", commit_message, "--no-verify") repo.git.commit("-m", commit_message, "--no-verify")
commit_hash = repo.head.commit.hexsha[:7] commit_hash = repo.head.commit.hexsha[:7]
self.io.tool(f"Commit {commit_hash} {commit_message}") self.io.tool_output(f"Commit {commit_hash} {commit_message}")
else: else:
self.io.tool_error("Skipped adding new files to the git repo.") self.io.tool_error("Skipped adding new files to the git repo.")
return return
@ -258,7 +258,7 @@ class Coder:
self.cur_messages = [] self.cur_messages = []
if inp.strip(): if inp.strip():
self.io.tool("Use up-arrow to retry previous command:", inp) self.io.tool_output("Use up-arrow to retry previous command:", inp)
return return
if not inp: if not inp:
@ -296,7 +296,7 @@ class Coder:
dict(role="assistant", content=content), dict(role="assistant", content=content),
] ]
self.io.tool() self.io.tool_output()
if interrupted: if interrupted:
return return
@ -366,7 +366,7 @@ class Coder:
return return
for rel_fname in mentioned_rel_fnames: for rel_fname in mentioned_rel_fnames:
self.io.tool(rel_fname) self.io.tool_output(rel_fname)
if not self.io.confirm_ask("Add these files to the chat?"): if not self.io.confirm_ask("Add these files to the chat?"):
return return
@ -476,9 +476,9 @@ class Coder:
edited.add(path) edited.add(path)
if utils.do_replace(full_path, original, updated, self.dry_run): if utils.do_replace(full_path, original, updated, self.dry_run):
if self.dry_run: if self.dry_run:
self.io.tool(f"Dry run, did not apply edit to {path}") self.io.tool_output(f"Dry run, did not apply edit to {path}")
else: else:
self.io.tool(f"Applied edit to {path}") self.io.tool_output(f"Applied edit to {path}")
else: else:
self.io.tool_error(f"Failed to apply edit to {path}") self.io.tool_error(f"Failed to apply edit to {path}")
@ -574,7 +574,7 @@ class Coder:
raise ValueError(f"Invalid value for 'which': {which}") raise ValueError(f"Invalid value for 'which': {which}")
if self.show_diffs or ask: if self.show_diffs or ask:
# don't use io.tool() because we don't want to log or further colorize # don't use io.tool_output() because we don't want to log or further colorize
print(diffs) print(diffs)
context = self.get_context_from_history(history) context = self.get_context_from_history(history)
@ -588,9 +588,9 @@ class Coder:
if ask: if ask:
if which == "repo_files": if which == "repo_files":
self.io.tool("Git repo has uncommitted changes.") self.io.tool_output("Git repo has uncommitted changes.")
else: else:
self.io.tool("Files have uncommitted changes.") self.io.tool_output("Files have uncommitted changes.")
res = self.io.prompt_ask( res = self.io.prompt_ask(
"Commit before the chat proceeds [y/n/commit message]?", "Commit before the chat proceeds [y/n/commit message]?",
@ -598,7 +598,7 @@ class Coder:
).strip() ).strip()
self.last_asked_for_commit_time = self.get_last_modified() self.last_asked_for_commit_time = self.get_last_modified()
self.io.tool() self.io.tool_output()
if res.lower() in ["n", "no"]: if res.lower() in ["n", "no"]:
self.io.tool_error("Skipped commmit.") self.io.tool_error("Skipped commmit.")
@ -611,7 +611,7 @@ class Coder:
full_commit_message = commit_message + "\n\n" + context full_commit_message = commit_message + "\n\n" + context
repo.git.commit("-m", full_commit_message, "--no-verify") repo.git.commit("-m", full_commit_message, "--no-verify")
commit_hash = repo.head.commit.hexsha[:7] commit_hash = repo.head.commit.hexsha[:7]
self.io.tool(f"Commit {commit_hash} {commit_message}") self.io.tool_output(f"Commit {commit_hash} {commit_message}")
return commit_hash, commit_message return commit_hash, commit_message

View file

@ -37,7 +37,7 @@ class Commands:
if cmd_method: if cmd_method:
return cmd_method(args) return cmd_method(args)
else: else:
self.io.tool(f"Error: Command {cmd_name} not found.") self.io.tool_output(f"Error: Command {cmd_name} not found.")
def run(self, inp): def run(self, inp):
words = inp.strip().split() words = inp.strip().split()
@ -110,7 +110,7 @@ class Commands:
self.io.tool_error("The last commit was not made by aider in this chat session.") self.io.tool_error("The last commit was not made by aider in this chat session.")
return return
self.coder.repo.git.reset("--hard", "HEAD~1") self.coder.repo.git.reset("--hard", "HEAD~1")
self.io.tool( self.io.tool_output(
f"{last_commit.message.strip()}\n" f"{last_commit.message.strip()}\n"
f"The above commit {self.coder.last_aider_commit_hash} " f"The above commit {self.coder.last_aider_commit_hash} "
"was reset and removed from git.\n" "was reset and removed from git.\n"
@ -131,7 +131,7 @@ class Commands:
commits = f"{self.coder.last_aider_commit_hash}~1" commits = f"{self.coder.last_aider_commit_hash}~1"
diff = self.coder.get_diffs(commits, self.coder.last_aider_commit_hash) diff = self.coder.get_diffs(commits, self.coder.last_aider_commit_hash)
# don't use io.tool() because we don't want to log or further colorize # don't use io.tool_output() because we don't want to log or further colorize
print(diff) print(diff)
def completions_add(self, partial): def completions_add(self, partial):
@ -177,7 +177,7 @@ class Commands:
abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file)) abs_file_path = os.path.abspath(os.path.join(self.coder.root, matched_file))
if abs_file_path not in self.coder.abs_fnames: if abs_file_path not in self.coder.abs_fnames:
self.coder.abs_fnames.add(abs_file_path) self.coder.abs_fnames.add(abs_file_path)
self.io.tool(f"Added {matched_file} to the chat") self.io.tool_output(f"Added {matched_file} to the chat")
added_fnames.append(matched_file) added_fnames.append(matched_file)
else: else:
self.io.tool_error(f"{matched_file} is already in the chat") self.io.tool_error(f"{matched_file} is already in the chat")
@ -214,7 +214,7 @@ class Commands:
for matched_file in matched_files: for matched_file in matched_files:
relative_fname = os.path.relpath(matched_file, self.coder.root) relative_fname = os.path.relpath(matched_file, self.coder.root)
self.coder.abs_fnames.remove(matched_file) self.coder.abs_fnames.remove(matched_file)
self.io.tool(f"Removed {relative_fname} from the chat") self.io.tool_output(f"Removed {relative_fname} from the chat")
def cmd_run(self, args): def cmd_run(self, args):
"Run a shell command and optionally add the output to the chat" "Run a shell command and optionally add the output to the chat"
@ -258,14 +258,14 @@ class Commands:
other_files.append(file) other_files.append(file)
if chat_files: if chat_files:
self.io.tool("Files in chat:\n") self.io.tool_output("Files in chat:\n")
for file in chat_files: for file in chat_files:
self.io.tool(f" {file}") self.io.tool_output(f" {file}")
if other_files: if other_files:
self.io.tool("\nRepo files not in the chat:\n") self.io.tool_output("\nRepo files not in the chat:\n")
for file in other_files: for file in other_files:
self.io.tool(f" {file}") self.io.tool_output(f" {file}")
def cmd_help(self, args): def cmd_help(self, args):
"Show help about all commands" "Show help about all commands"
@ -275,6 +275,6 @@ class Commands:
cmd_method = getattr(self, cmd_method_name, None) cmd_method = getattr(self, cmd_method_name, None)
if cmd_method: if cmd_method:
description = cmd_method.__doc__ description = cmd_method.__doc__
self.io.tool(f"{cmd} {description}") self.io.tool_output(f"{cmd} {description}")
else: else:
self.io.tool(f"{cmd} No description available.") self.io.tool_output(f"{cmd} No description available.")

View file

@ -217,7 +217,7 @@ class InputOutput:
style = dict(style=self.tool_error_color) if self.tool_error_color else dict() style = dict(style=self.tool_error_color) if self.tool_error_color else dict()
self.console.print(message, **style) self.console.print(message, **style)
def tool(self, *messages, log_only=False): def tool_output(self, *messages, log_only=False):
if messages: if messages:
hist = " ".join(messages) hist = " ".join(messages)
hist = f"{hist.strip()}" hist = f"{hist.strip()}"

View file

@ -182,12 +182,12 @@ def main(args=None, input=None, output=None):
if args.verbose: if args.verbose:
show = parser.format_values() show = parser.format_values()
io.tool(show) io.tool_output(show)
io.tool("Option settings:") io.tool_output("Option settings:")
for arg, val in sorted(vars(args).items()): for arg, val in sorted(vars(args).items()):
io.tool(f" - {arg}: {val}") io.tool_output(f" - {arg}: {val}")
io.tool(*sys.argv, log_only=True) io.tool_output(*sys.argv, log_only=True)
if not args.openai_api_key: if not args.openai_api_key:
io.tool_error("No OpenAI API key provided. Use --openai-api-key or env OPENAI_API_KEY.") io.tool_error("No OpenAI API key provided. Use --openai-api-key or env OPENAI_API_KEY.")
@ -216,7 +216,7 @@ def main(args=None, input=None, output=None):
coder.update_files(content, inp="") coder.update_files(content, inp="")
return return
io.tool("Use /help to see in-chat commands.") io.tool_output("Use /help to see in-chat commands.")
coder.run() coder.run()