-
Notifications
You must be signed in to change notification settings - Fork 44.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use click to parse arguments #2373
Use click to parse arguments #2373
Conversation
Please see my previous attempt to get this in #1184 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement to the CLI!
One small request: since there is only one command as of now, it's best if people can still run ./run.sh
without any subcommands. Click seems to support this with click-default-group.
I'm not sure it's wise using a dependence with only 50 stars and hasn't been touched for 4 years |
It has good test coverage, is used by 3.7k projects/people, and we could pin it to the current version if we want to be certain it keeps working. There are also ways to achieve the same in bash, but the lib seems like a cleaner option. |
@Pwuts Figured out how to do it without adding another dependency: ➜ Auto-GPT git:(click-arg-pasing) ✗ ./run.sh
All packages are installed.
Welcome to Auto-GPT! run with '--help' for more information.
Create an AI-Assistant: Enter the name of your AI and its role below. Entering nothing will load defaults.
Name your AI: For example, 'Entrepreneur-GPT'
AI Name: help:
Here is some sample code showing how a subcommand can be added: @main.command()
def test() -> None:
"""An example sub command"""
print("test") Running with test passed as the subcommand:
|
click is also good because it handles some cases that argparse implied such as list arguments which is the biggest PITA with argparse (there is some nasty implied ordering in argparse)... If you wanted to add some tests could do something like import click
from click.testing import CliRunner
def test_cli():
runner = CliRunner()
result = runner.invoke(path.to.cli, ["my-cli-command", "my-click-options", "my-click-args"])
assert result.exit_code == 0 |
autogpt/__main__.py
Outdated
) | ||
agent.start_interaction_loop() | ||
""" | ||
Welcome to AutoGPT an experimental open-source application showcasing the capabilities of the GPT-4 pushing the boundaries of AI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
punctuation?
…sing Use click to parse arguments
Background
This PR changes the argument parsing library from
argparse
toclick
. The primary reason for this switch is to leverage the benefits provided byclick
, while maintaining backward compatibility with the existing implementation.Click
is a powerful and flexible library for creating command-line interfaces, offering several advantages overargparse
, such as a more intuitive and consistent API, better error messages, automatic generation of help messages, and advanced features like command chaining and nested commands.Changes
Benefits of Click
Documentation
The code changes include in-code comments to describe the new click decorators and options. The external documentation will be updated to reflect the change from argparse to click.
Test Plan
PR Quality Checklist