aider: work in progress

# Context:
USER: does `configargparse` have a way to group the args into sections so they display grouped in --help?
ASSISTANT: Yes, `configargparse` supports argument grouping. This is done using the `add_argument_group` method of the `ArgumentParser` object. This method creates a new group of arguments and any arguments added to this group will be displayed together in the help message.

Here's an example of how you can group arguments:

```python
group = parser.add_argument_group('group name')
group.add_argument('--arg1')
group.add_argument('--arg2')
```

In the help message, `arg1` and `arg2` will be displayed under the section 'group name'.
USER: can you update the code to group them into a few sensible groups?
ASSISTANT: Sure, I can group the arguments in the `main` function of the `aider/main.py` file into several groups. Here's how I would do it:

1. General arguments: version, config, files
2. History files: input-history-file, chat-history-file
3. Model settings: model, edit-format
4. Output settings: pretty, no-pretty, no-stream, user-input-color, tool-output-color, tool-error-color, assistant-output-color, code-theme
5. Git settings: no-git, auto-commits, no-auto-commits, dirty-commits, no-dirty-commits
6. OpenAI settings: openai-api-key, openai-api-base
7. Other settings: dry-run, show-diffs, map-tokens, yes, verbose, message

Here's the updated code:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
    )

    parser.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
        help="Show the version number and exit",
    )

    parser.add_argument(
        "-c",
        "--config",
        is_config_file=True,
        metavar="CONFIG_FILE",
        help=(
            "Specify the config file (default: search for .aider.conf.yml in git root, cwd"
            " or home directory)"
        ),
    )

    parser.add_argument(
        "files",
        metavar="FILE",
        nargs="*",
        help="a list of source code files (optional)",
    )
    default_input_history_file = (
        os.path.join(git_root, ".aider.input.history") if git_root else ".aider.input.history"
    )
    default_chat_history_file = (
        os.path.join(git_root, ".aider.chat.history.md") if git_root else ".aider.chat.history.md"
    )

    parser.add_argument(
        "--input-history-file",
        metavar="INPUT_HISTORY_FILE",
        default=default_input_history_file,
        help=f"Specify the chat input history file (default: {default_input_history_file})",
    )
    parser.add_argument(
        "--chat-history-file",
        metavar="CHAT_HISTORY_FILE",
        default=default_chat_history_file,
        help=f"Specify the chat history file (default: {default_chat_history_file})",
    )
    parser.add_argument(
        "--model",
        metavar="MODEL",
        default=models.GPT4.name,
        help=f"Specify the model to use for the main chat (default: {models.GPT4.name})",
    )
    parser.add_argument(
        "-3",
        action="store_const",
        dest="model",
        const=models.GPT35_16k.name,
        help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)",
    )
    parser.add_argument(
        "--edit-format",
        metavar="EDIT_FORMAT",
        default=None,
        help="Specify what edit format GPT should use (default depends on model)",
    )
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
    parser.add_argument(
        "--no-stream",
        action="store_false",
        dest="stream",
        default=True,
        help="Disable streaming responses",
    )
    parser.add_argument(
        "--no-git",
        action="store_false",
        dest="git",
        default=True,
        help="Do not look for a git repo",
    )
    parser.add_argument(
        "--user-input-color",
        default="green",
        help="Set the color for user input (default: green)",
    )
    parser.add_argument(
        "--tool-output-color",
        default=None,
        help="Set the color for tool output (default: None)",
    )
    parser.add_argument(
        "--tool-error-color",
        default="red",
        help="Set the color for tool error messages (default: red)",
    )
    parser.add_argument(
        "--assistant-output-color",
        default="blue",
        help="Set the color for assistant output (default: blue)",
    )
    parser.add_argument(
        "--code-theme",
        default="default",
        help=(
            "Set the markdown code theme (default: default, other options include monokai,"
            " solarized-dark, solarized-light)"
        ),
    )
    parser.add_argument(
        "--apply",
        metavar="FILE",
        help="Apply the changes from the given file instead of running the chat (debug)",
    )
    parser.add_argument(
        "--auto-commits",
        action="store_true",
        dest="auto_commits",
        default=True,
        help="Enable auto commit of GPT changes (default: True)",
    )

    parser.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of GPT changes (implies --no-dirty-commits)",
    )
    parser.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable commits when repo is found dirty",
        default=True,
    )
    parser.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )
    parser.add_argument(
        "--encoding",
        default="utf-8",
        help="Specify the encoding to use when reading files (default: utf-8)",
    )
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )
    parser.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    parser.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    parser.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    parser.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
=======
    parser = configargparse.ArgumentParser(
        description="aider is GPT powered coding in your terminal",
        add_config_file_help=True,
        default_config_files=default_config_files,
        config_file_parser_class=configargparse.YAMLConfigFileParser,
        auto_env_var_prefix="AIDER_",
    )

    general_group = parser.add_argument_group('General')
    general_group.add_argument(
        "--version",
        action="version",
        version=f"%(prog)s {__version__}",
        help="Show the version number and exit",
    )
    general_group.add_argument(
        "-c",
        "--config",
        is_config_file=True,
        metavar="CONFIG_FILE",
        help=(
            "Specify the config file (default: search for .aider.conf.yml in git root, cwd"
            " or home directory)"
        ),
    )
    general_group.add_argument(
        "files",
        metavar="FILE",
        nargs="*",
        help="a list of source code files (optional)",
    )

    history_group = parser.add_argument_group('History Files')
    default_input_history_file = (
        os.path.join(git_root, ".aider.input.history") if git_root else ".aider.input.history"
    )
    default_chat_history_file = (
        os.path.join(git_root, ".aider.chat.history.md") if git_root else ".aider.chat.history.md"
    )
    history_group.add_argument(
        "--input-history-file",
        metavar="INPUT_HISTORY_FILE",
        default=default_input_history_file,
        help=f"Specify the chat input history file (default: {default_input_history_file})",
    )
    history_group.add_argument(
        "--chat-history-file",
        metavar="CHAT_HISTORY_FILE",
        default=default_chat_history_file,
        help=f"Specify the chat history file (default: {default_chat_history_file})",
    )

    model_group = parser.add_argument_group('Model Settings')
    model_group.add_argument(
        "--model",
        metavar="MODEL",
        default=models.GPT4.name,
        help=f"Specify the model to use for the main chat (default: {models.GPT4.name})",
    )
    model_group.add_argument(
        "-3",
        action="store_const",
        dest="model",
        const=models.GPT35_16k.name,
        help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)",
    )
    model_group.add_argument(
        "--edit-format",
        metavar="EDIT_FORMAT",
        default=None,
        help="Specify what edit format GPT should use (default depends on model)",
    )

    output_group = parser.add_argument_group('Output Settings')
    output_group.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    output_group.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
    output_group.add_argument(
        "--no-stream",
        action="store_false",
        dest="stream",
        default=True,
        help="Disable streaming responses",
    )
    output_group.add_argument(
        "--user-input-color",
        default="green",
        help="Set the color for user input (default: green)",
    )
    output_group.add_argument(
        "--tool-output-color",
        default=None,
        help="Set the color for tool output (default: None)",
    )
    output_group.add_argument(
        "--tool-error-color",
        default="red",
        help="Set the color for tool error messages (default: red)",
    )
    output_group.add_argument(
        "--assistant-output-color",
        default="blue",
        help="Set the color for assistant output (default: blue)",
    )
    output_group.add_argument(
        "--code-theme",
        default="default",
        help=(
            "Set the markdown code theme (default: default, other options include monokai,"
            " solarized-dark, solarized-light)"
        ),
    )

    git_group = parser.add_argument_group('Git Settings')
    git_group.add_argument(
        "--no-git",
        action="store_false",
        dest="git",
        default=True,
        help="Do not look for a git repo",
    )
    git_group.add_argument(
        "--auto-commits",
        action="store_true",
        dest="auto_commits",
        default=True,
        help="Enable auto commit of GPT changes (default: True)",
    )
    git_group.add_argument(
        "--no-auto-commits",
        action="store_false",
        dest="auto_commits",
        help="Disable auto commit of GPT changes (implies --no-dirty-commits)",
    )
    git_group.add_argument(
        "--dirty-commits",
        action="store_true",
        dest="dirty_commits",
        help="Enable commits when repo is found dirty",
        default=True,
    )
    git_group.add_argument(
        "--no-dirty-commits",
        action="store_false",
        dest="dirty_commits",
        help="Disable commits when repo is found dirty",
    )

    openai_group = parser.add_argument_group('OpenAI Settings')
    openai_group.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    openai_group.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
    )

    other_group = parser.add_argument_group('Other Settings')
    other_group.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--show-diffs",
        action="store_true",
        help="Show diffs when committing changes (default: False)",
        default=False,
    )
    other_group.add_argument(
        "--map-tokens",
        type=int,
        default=1024,
        help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
    )
    other_group.add_argument(
        "--yes",
        action="store_true",
        help="Always say yes to every confirmation",
        default=None,
    )
    other_group.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        help="Enable verbose output",
        default=False,
    )
    other_group.add_argument(
        "--message",
        "--msg",
        "-m",
        metavar="COMMAND",
        help="Specify a single message to send GPT, process reply then exit (disables chat mode)",
    )
>>>>>>> UPDATED
```

This will make the help message more organized and easier to read.
This commit is contained in:
Paul Gauthier 2023-07-08 07:06:30 -07:00
parent 90168560a5
commit 5590bbd6b8

View file

@ -42,14 +42,14 @@ def main(args=None, input=None, output=None):
auto_env_var_prefix="AIDER_", auto_env_var_prefix="AIDER_",
) )
parser.add_argument( general_group = parser.add_argument_group('General')
general_group.add_argument(
"--version", "--version",
action="version", action="version",
version=f"%(prog)s {__version__}", version=f"%(prog)s {__version__}",
help="Show the version number and exit", help="Show the version number and exit",
) )
general_group.add_argument(
parser.add_argument(
"-c", "-c",
"--config", "--config",
is_config_file=True, is_config_file=True,
@ -59,98 +59,95 @@ def main(args=None, input=None, output=None):
" or home directory)" " or home directory)"
), ),
) )
general_group.add_argument(
parser.add_argument(
"files", "files",
metavar="FILE", metavar="FILE",
nargs="*", nargs="*",
help="a list of source code files (optional)", help="a list of source code files (optional)",
) )
history_group = parser.add_argument_group('History Files')
default_input_history_file = ( default_input_history_file = (
os.path.join(git_root, ".aider.input.history") if git_root else ".aider.input.history" os.path.join(git_root, ".aider.input.history") if git_root else ".aider.input.history"
) )
default_chat_history_file = ( default_chat_history_file = (
os.path.join(git_root, ".aider.chat.history.md") if git_root else ".aider.chat.history.md" os.path.join(git_root, ".aider.chat.history.md") if git_root else ".aider.chat.history.md"
) )
history_group.add_argument(
parser.add_argument(
"--input-history-file", "--input-history-file",
metavar="INPUT_HISTORY_FILE", metavar="INPUT_HISTORY_FILE",
default=default_input_history_file, default=default_input_history_file,
help=f"Specify the chat input history file (default: {default_input_history_file})", help=f"Specify the chat input history file (default: {default_input_history_file})",
) )
parser.add_argument( history_group.add_argument(
"--chat-history-file", "--chat-history-file",
metavar="CHAT_HISTORY_FILE", metavar="CHAT_HISTORY_FILE",
default=default_chat_history_file, default=default_chat_history_file,
help=f"Specify the chat history file (default: {default_chat_history_file})", help=f"Specify the chat history file (default: {default_chat_history_file})",
) )
parser.add_argument(
model_group = parser.add_argument_group('Model Settings')
model_group.add_argument(
"--model", "--model",
metavar="MODEL", metavar="MODEL",
default=models.GPT4.name, default=models.GPT4.name,
help=f"Specify the model to use for the main chat (default: {models.GPT4.name})", help=f"Specify the model to use for the main chat (default: {models.GPT4.name})",
) )
parser.add_argument( model_group.add_argument(
"-3", "-3",
action="store_const", action="store_const",
dest="model", dest="model",
const=models.GPT35_16k.name, const=models.GPT35_16k.name,
help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)", help=f"Use {models.GPT35_16k.name} model for the main chat (gpt-4 is better)",
) )
parser.add_argument( model_group.add_argument(
"--edit-format", "--edit-format",
metavar="EDIT_FORMAT", metavar="EDIT_FORMAT",
default=None, default=None,
help="Specify what edit format GPT should use (default depends on model)", help="Specify what edit format GPT should use (default depends on model)",
) )
parser.add_argument(
output_group = parser.add_argument_group('Output Settings')
output_group.add_argument(
"--pretty", "--pretty",
action="store_true", action="store_true",
default=True, default=True,
help="Enable pretty, colorized output (default: True)", help="Enable pretty, colorized output (default: True)",
) )
parser.add_argument( output_group.add_argument(
"--no-pretty", "--no-pretty",
action="store_false", action="store_false",
dest="pretty", dest="pretty",
help="Disable pretty, colorized output", help="Disable pretty, colorized output",
) )
parser.add_argument( output_group.add_argument(
"--no-stream", "--no-stream",
action="store_false", action="store_false",
dest="stream", dest="stream",
default=True, default=True,
help="Disable streaming responses", help="Disable streaming responses",
) )
parser.add_argument( output_group.add_argument(
"--no-git",
action="store_false",
dest="git",
default=True,
help="Do not look for a git repo",
)
parser.add_argument(
"--user-input-color", "--user-input-color",
default="green", default="green",
help="Set the color for user input (default: green)", help="Set the color for user input (default: green)",
) )
parser.add_argument( output_group.add_argument(
"--tool-output-color", "--tool-output-color",
default=None, default=None,
help="Set the color for tool output (default: None)", help="Set the color for tool output (default: None)",
) )
parser.add_argument( output_group.add_argument(
"--tool-error-color", "--tool-error-color",
default="red", default="red",
help="Set the color for tool error messages (default: red)", help="Set the color for tool error messages (default: red)",
) )
parser.add_argument( output_group.add_argument(
"--assistant-output-color", "--assistant-output-color",
default="blue", default="blue",
help="Set the color for assistant output (default: blue)", help="Set the color for assistant output (default: blue)",
) )
parser.add_argument( output_group.add_argument(
"--code-theme", "--code-theme",
default="default", default="default",
help=( help=(
@ -158,87 +155,89 @@ def main(args=None, input=None, output=None):
" solarized-dark, solarized-light)" " solarized-dark, solarized-light)"
), ),
) )
parser.add_argument(
"--apply", git_group = parser.add_argument_group('Git Settings')
metavar="FILE", git_group.add_argument(
help="Apply the changes from the given file instead of running the chat (debug)", "--no-git",
action="store_false",
dest="git",
default=True,
help="Do not look for a git repo",
) )
parser.add_argument( git_group.add_argument(
"--auto-commits", "--auto-commits",
action="store_true", action="store_true",
dest="auto_commits", dest="auto_commits",
default=True, default=True,
help="Enable auto commit of GPT changes (default: True)", help="Enable auto commit of GPT changes (default: True)",
) )
git_group.add_argument(
parser.add_argument(
"--no-auto-commits", "--no-auto-commits",
action="store_false", action="store_false",
dest="auto_commits", dest="auto_commits",
help="Disable auto commit of GPT changes (implies --no-dirty-commits)", help="Disable auto commit of GPT changes (implies --no-dirty-commits)",
) )
parser.add_argument( git_group.add_argument(
"--dirty-commits", "--dirty-commits",
action="store_true", action="store_true",
dest="dirty_commits", dest="dirty_commits",
help="Enable commits when repo is found dirty", help="Enable commits when repo is found dirty",
default=True, default=True,
) )
parser.add_argument( git_group.add_argument(
"--no-dirty-commits", "--no-dirty-commits",
action="store_false", action="store_false",
dest="dirty_commits", dest="dirty_commits",
help="Disable commits when repo is found dirty", help="Disable commits when repo is found dirty",
) )
parser.add_argument(
"--encoding", openai_group = parser.add_argument_group('OpenAI Settings')
default="utf-8", openai_group.add_argument(
help="Specify the encoding to use when reading files (default: utf-8)",
)
parser.add_argument(
"--openai-api-key", "--openai-api-key",
metavar="OPENAI_API_KEY", metavar="OPENAI_API_KEY",
help="Specify the OpenAI API key", help="Specify the OpenAI API key",
env_var="OPENAI_API_KEY", env_var="OPENAI_API_KEY",
) )
parser.add_argument( openai_group.add_argument(
"--openai-api-base", "--openai-api-base",
metavar="OPENAI_API_BASE", metavar="OPENAI_API_BASE",
default="https://api.openai.com/v1", default="https://api.openai.com/v1",
help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)", help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1)",
) )
parser.add_argument(
other_group = parser.add_argument_group('Other Settings')
other_group.add_argument(
"--dry-run", "--dry-run",
action="store_true", action="store_true",
help="Perform a dry run without applying changes (default: False)", help="Perform a dry run without applying changes (default: False)",
default=False, default=False,
) )
parser.add_argument( other_group.add_argument(
"--show-diffs", "--show-diffs",
action="store_true", action="store_true",
help="Show diffs when committing changes (default: False)", help="Show diffs when committing changes (default: False)",
default=False, default=False,
) )
parser.add_argument( other_group.add_argument(
"--map-tokens", "--map-tokens",
type=int, type=int,
default=1024, default=1024,
help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)", help="Max number of tokens to use for repo map, use 0 to disable (default: 1024)",
) )
parser.add_argument( other_group.add_argument(
"--yes", "--yes",
action="store_true", action="store_true",
help="Always say yes to every confirmation", help="Always say yes to every confirmation",
default=None, default=None,
) )
parser.add_argument( other_group.add_argument(
"-v", "-v",
"--verbose", "--verbose",
action="store_true", action="store_true",
help="Enable verbose output", help="Enable verbose output",
default=False, default=False,
) )
parser.add_argument( other_group.add_argument(
"--message", "--message",
"--msg", "--msg",
"-m", "-m",