From b3e79ed6772598355fe2dcea7ad938f4a77988ea Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Sun, 16 Jul 2023 13:18:29 +0300 Subject: [PATCH] cli.py - modify command line for a more coherent command invokation --- pr_agent/cli.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/pr_agent/cli.py b/pr_agent/cli.py index 78a795ea..da94f9a2 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -10,29 +10,48 @@ from pr_agent.tools.pr_reviewer import PRReviewer def run(): - parser = argparse.ArgumentParser(description='AI based pull request analyzer') + parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage="""\ +Usage: cli.py --pr-url []. + +Supported commands: +review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement. +ask / ask_question [question] - Ask a question about the PR. +describe / describe_pr - Modify the PR title and description based on the PR's contents. +improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit. +""") parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True) - parser.add_argument('--question', type=str, help='Optional question to ask', required=False) - parser.add_argument('--pr_description', action='store_true', required=False) - parser.add_argument('--pr_code_suggestions', action='store_true', required=False) + parser.add_argument('command', type=str, help='The', choices=['review', 'review_pr', + 'ask', 'ask_question', + 'describe', 'describe_pr', + 'improve', 'improve_code'], default='review') + parser.add_argument('rest', nargs=argparse.REMAINDER, default=[]) args = parser.parse_args() logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO")) - if args.question: - print(f"Question: {args.question} about PR {args.pr_url}") - reviewer = PRQuestions(args.pr_url, args.question) + command = args.command.lower() + if command in ['ask', 'ask_question']: + question = ' '.join(args.rest).strip() + if len(question) == 0: + print("Please specify a question") + parser.print_help() + return + print(f"Question: {question} about PR {args.pr_url}") + reviewer = PRQuestions(args.pr_url, question) asyncio.run(reviewer.answer()) - elif args.pr_description: + elif command in ['describe', 'describe_pr']: print(f"PR description: {args.pr_url}") reviewer = PRDescription(args.pr_url) asyncio.run(reviewer.describe()) - elif args.pr_code_suggestions: + elif command in ['improve', 'improve_code']: print(f"PR code suggestions: {args.pr_url}") reviewer = PRCodeSuggestions(args.pr_url) asyncio.run(reviewer.suggest()) - else: + elif command in ['review', 'review_pr']: print(f"Reviewing PR: {args.pr_url}") reviewer = PRReviewer(args.pr_url, cli_mode=True) asyncio.run(reviewer.review()) + else: + print(f"Unknown command: {command}") + parser.print_help() if __name__ == '__main__':