mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
refactored parser, args
This commit is contained in:
parent
221ddbb9ea
commit
5a01ba70a6
2 changed files with 55 additions and 40 deletions
13
aider/gui.py
13
aider/gui.py
|
@ -143,6 +143,9 @@ class GUI:
|
||||||
st.title("Aider")
|
st.title("Aider")
|
||||||
# self.cmds_tab, self.settings_tab = st.tabs(["Commands", "Settings"])
|
# self.cmds_tab, self.settings_tab = st.tabs(["Commands", "Settings"])
|
||||||
|
|
||||||
|
def do_settings_tab(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def do_cmd_tab(self):
|
def do_cmd_tab(self):
|
||||||
with st.sidebar:
|
with st.sidebar:
|
||||||
# self.do_recommended_actions()
|
# self.do_recommended_actions()
|
||||||
|
@ -336,9 +339,9 @@ class GUI:
|
||||||
|
|
||||||
return st.button(args, **kwargs)
|
return st.button(args, **kwargs)
|
||||||
|
|
||||||
def __init__(self, coder, state):
|
def __init__(self):
|
||||||
self.coder = coder
|
self.coder = get_coder()
|
||||||
self.state = state
|
self.state = get_state()
|
||||||
|
|
||||||
# Force the coder to cooperate, regardless of cmd line args
|
# Force the coder to cooperate, regardless of cmd line args
|
||||||
self.coder.yield_stream = True
|
self.coder.yield_stream = True
|
||||||
|
@ -500,9 +503,7 @@ class GUI:
|
||||||
def gui_main():
|
def gui_main():
|
||||||
st.set_page_config(layout="wide")
|
st.set_page_config(layout="wide")
|
||||||
|
|
||||||
coder = get_coder()
|
GUI()
|
||||||
state = get_state()
|
|
||||||
GUI(coder, state)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -122,25 +122,7 @@ def check_gitignore(git_root, io, ask=True):
|
||||||
io.tool_output(f"Added {pat} to .gitignore")
|
io.tool_output(f"Added {pat} to .gitignore")
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False):
|
def get_parser(default_config_files, git_root):
|
||||||
if argv is None:
|
|
||||||
argv = sys.argv[1:]
|
|
||||||
|
|
||||||
if force_git_root:
|
|
||||||
git_root = force_git_root
|
|
||||||
else:
|
|
||||||
git_root = get_git_root()
|
|
||||||
|
|
||||||
conf_fname = Path(".aider.conf.yml")
|
|
||||||
|
|
||||||
default_config_files = [conf_fname.resolve()] # CWD
|
|
||||||
if git_root:
|
|
||||||
git_conf = Path(git_root) / conf_fname # git root
|
|
||||||
if git_conf not in default_config_files:
|
|
||||||
default_config_files.append(git_conf)
|
|
||||||
default_config_files.append(Path.home() / conf_fname) # homedir
|
|
||||||
default_config_files = list(map(str, default_config_files))
|
|
||||||
|
|
||||||
parser = configargparse.ArgumentParser(
|
parser = configargparse.ArgumentParser(
|
||||||
description="aider is GPT powered coding in your terminal",
|
description="aider is GPT powered coding in your terminal",
|
||||||
add_config_file_help=True,
|
add_config_file_help=True,
|
||||||
|
@ -497,6 +479,49 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def format_settings(parser, args):
|
||||||
|
show = scrub_sensitive_info(args, parser.format_values())
|
||||||
|
show += "\n"
|
||||||
|
show += "Option settings:\n"
|
||||||
|
for arg, val in sorted(vars(args).items()):
|
||||||
|
if val:
|
||||||
|
val = scrub_sensitive_info(args, str(val))
|
||||||
|
show += f" - {arg}: {val}\n"
|
||||||
|
return show
|
||||||
|
|
||||||
|
|
||||||
|
def scrub_sensitive_info(args, text):
|
||||||
|
# Replace sensitive information with placeholder
|
||||||
|
if text and args.openai_api_key:
|
||||||
|
text = text.replace(args.openai_api_key, "***")
|
||||||
|
if text and args.anthropic_api_key:
|
||||||
|
text = text.replace(args.anthropic_api_key, "***")
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False):
|
||||||
|
if argv is None:
|
||||||
|
argv = sys.argv[1:]
|
||||||
|
|
||||||
|
if force_git_root:
|
||||||
|
git_root = force_git_root
|
||||||
|
else:
|
||||||
|
git_root = get_git_root()
|
||||||
|
|
||||||
|
conf_fname = Path(".aider.conf.yml")
|
||||||
|
|
||||||
|
default_config_files = [conf_fname.resolve()] # CWD
|
||||||
|
if git_root:
|
||||||
|
git_conf = Path(git_root) / conf_fname # git root
|
||||||
|
if git_conf not in default_config_files:
|
||||||
|
default_config_files.append(git_conf)
|
||||||
|
default_config_files.append(Path.home() / conf_fname) # homedir
|
||||||
|
default_config_files = list(map(str, default_config_files))
|
||||||
|
|
||||||
|
parser = get_parser(default_config_files, git_root)
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
if args.dark_mode:
|
if args.dark_mode:
|
||||||
|
@ -582,24 +607,13 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
if args.gitignore:
|
if args.gitignore:
|
||||||
check_gitignore(git_root, io)
|
check_gitignore(git_root, io)
|
||||||
|
|
||||||
def scrub_sensitive_info(text):
|
|
||||||
# Replace sensitive information with placeholder
|
|
||||||
if text and args.openai_api_key:
|
|
||||||
text = text.replace(args.openai_api_key, "***")
|
|
||||||
if text and args.anthropic_api_key:
|
|
||||||
text = text.replace(args.anthropic_api_key, "***")
|
|
||||||
return text
|
|
||||||
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
show = scrub_sensitive_info(parser.format_values())
|
show = format_settings(parser, args)
|
||||||
io.tool_output(show)
|
io.tool_output(show)
|
||||||
io.tool_output("Option settings:")
|
|
||||||
for arg, val in sorted(vars(args).items()):
|
|
||||||
if val:
|
|
||||||
val = scrub_sensitive_info(str(val))
|
|
||||||
io.tool_output(f" - {arg}: {val}")
|
|
||||||
|
|
||||||
io.tool_output(*map(scrub_sensitive_info, sys.argv), log_only=True)
|
cmd_line = " ".join(sys.argv)
|
||||||
|
cmd_line = scrub_sensitive_info(args, cmd_line)
|
||||||
|
io.tool_output(cmd_line, log_only=True)
|
||||||
|
|
||||||
if args.anthropic_api_key:
|
if args.anthropic_api_key:
|
||||||
os.environ["ANTHROPIC_API_KEY"] = args.anthropic_api_key
|
os.environ["ANTHROPIC_API_KEY"] = args.anthropic_api_key
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue