mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44:59 +00:00
aider: Add argument formatter to print arguments in a specified format.
# Aider chat conversation: USER: Add an args formatter that prints out args like this: ## Output Settings: ### --dark-mode Use colors suitable for a dark terminal background Default: False ### --light-mode Use colors suitable for a light terminal background Default: False ... ASSISTANT: To add an argument formatter that prints out arguments in the specified format, we need to: 1. Create a new formatter class. 2. Update the `get_help` function to use this new formatter. Here are the changes: 1. Create a new file `aider/args_formatter.py` with the custom formatter class. 2. Update `aider/args.py` to use this new formatter. Let's start with the new file: aider/args_formatter.py ```python <<<<<<< SEARCH ======= import argparse class CustomHelpFormatter(argparse.HelpFormatter): def start_section(self, heading): super().start_section(f"## {heading}:") def _format_action(self, action): parts = [] if action.help: parts.append(f"### --{action.dest}") parts.append(action.help) if action.default is not argparse.SUPPRESS: parts.append(f"Default: {action.default}") return "\n".join(parts) def _format_action_invocation(self, action): return "" def _format_args(self, action, default_metavar): return "" >>>>>>> REPLACE ``` Next, update `aider/args.py` to use this new formatter: aider/args.py ```python <<<<<<< SEARCH from aider import __version__, models ======= from aider import __version__, models from aider.args_formatter import CustomHelpFormatter >>>>>>> REPLACE ``` aider/args.py ```python <<<<<<< SEARCH description="aider is GPT powered coding in your terminal", ======= description="aider is GPT powered coding in your terminal", formatter_class=CustomHelpFormatter, >>>>>>> REPLACE ``` aider/args.py ```python <<<<<<< SEARCH parser = get_parser([], None) ======= parser = get_parser([], None) parser.formatter_class = CustomHelpFormatter >>>>>>> REPLACE ```
This commit is contained in:
parent
0e5342fdb8
commit
e7aafd9590
2 changed files with 23 additions and 0 deletions
|
@ -7,11 +7,13 @@ import sys
|
|||
import configargparse
|
||||
|
||||
from aider import __version__, models
|
||||
from aider.args_formatter import CustomHelpFormatter
|
||||
|
||||
|
||||
def get_parser(default_config_files, git_root):
|
||||
parser = configargparse.ArgumentParser(
|
||||
description="aider is GPT powered coding in your terminal",
|
||||
formatter_class=CustomHelpFormatter,
|
||||
add_config_file_help=True,
|
||||
default_config_files=default_config_files,
|
||||
auto_env_var_prefix="AIDER_",
|
||||
|
@ -455,6 +457,7 @@ def get_help():
|
|||
os.environ["COLUMNS"] = "100"
|
||||
sys.argv[0] = "aider"
|
||||
parser = get_parser([], None)
|
||||
parser.formatter_class = CustomHelpFormatter
|
||||
return parser.format_help()
|
||||
|
||||
|
||||
|
|
20
aider/args_formatter.py
Normal file
20
aider/args_formatter.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
import argparse
|
||||
|
||||
class CustomHelpFormatter(argparse.HelpFormatter):
|
||||
def start_section(self, heading):
|
||||
super().start_section(f"## {heading}:")
|
||||
|
||||
def _format_action(self, action):
|
||||
parts = []
|
||||
if action.help:
|
||||
parts.append(f"### --{action.dest}")
|
||||
parts.append(action.help)
|
||||
if action.default is not argparse.SUPPRESS:
|
||||
parts.append(f"Default: {action.default}")
|
||||
return "\n".join(parts)
|
||||
|
||||
def _format_action_invocation(self, action):
|
||||
return ""
|
||||
|
||||
def _format_args(self, action, default_metavar):
|
||||
return ""
|
Loading…
Add table
Add a link
Reference in a new issue