aider is AI pair programming in your terminal https://aider.chat/
Find a file
Paul Gauthier 10192dddcd Add env_prefix variable and load default values from environment variables.
# Context:
USER: in main add a var called env_prefix="CODER_" then for every parser arg load the default from os.environ using that prefix and the uppercase, snakecase of the arg name as the env var name
ASSISTANT: To add an `env_prefix` variable and load the default values for each argument from the environment variables, you can update the `main` function as follows:

```python
coder.py
<<<<<<< ORIGINAL
def main():
    parser = argparse.ArgumentParser(description="Chat with GPT about code")
    parser.add_argument(
        "files", metavar="FILE", nargs="+", help="a list of source code files"
    )
    parser.add_argument(
        "-3",
        "--gpt-3-5-turbo",
        action="store_true",
        help="Only use gpt-3.5-turbo, not gpt-4",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        default=True,
        help="Disable prettyd output of GPT responses",
    )
    parser.add_argument(
        "--apply",
        metavar="FILE",
        help="Apply the changes from the given file instead of running the chat",
    )
    parser.add_argument(
        "--commit",
        action="store_true",
        help="Commit dirty files without confirmation",
    )
=======
def main():
    env_prefix = "CODER_"

    parser = argparse.ArgumentParser(description="Chat with GPT about code")
    parser.add_argument(
        "files", metavar="FILE", nargs="+", help="a list of source code files",
        default=os.environ.get(env_prefix + "FILES", "").split()
    )
    parser.add_argument(
        "-3",
        "--gpt-3-5-turbo",
        action="store_true",
        help="Only use gpt-3.5-turbo, not gpt-4",
        default=bool(os.environ.get(env_prefix + "GPT_3_5_TURBO", False))
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        default=True,
        help="Disable prettyd output of GPT responses",
        default=bool(os.environ.get(env_prefix + "NO_PRETTY", True))
    )
    parser.add_argument(
        "--apply",
        metavar="FILE",
        help="Apply the changes from the given file instead of running the chat",
        default=os.environ.get(env_prefix + "APPLY", None)
    )
    parser.add_argument(
        "--commit",
        action="store_true",
        help="Commit dirty files without confirmation",
        default=bool(os.environ.get(env_prefix + "COMMIT", False))
    )
>>>>>>> UPDATED
```

This change adds the `env_prefix` variable and sets the default values for each argument using the `os.environ.get()` function with the appropriate environment variable name.
2023-05-08 23:06:56 -07:00
.flake8 debug 2023-05-08 22:55:55 -07:00
.pre-commit-config.yaml added flake8 2023-05-07 22:13:57 -07:00
coder.py Add env_prefix variable and load default values from environment variables. 2023-05-08 23:06:56 -07:00
dump.py init 2023-04-19 09:03:23 -07:00
prompts.py prompts 2023-05-08 22:07:02 -07:00