From d22877a0f1a206ed7697fe4d773ef576bbf30aa3 Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Sat, 9 Sep 2023 15:38:40 +0200 Subject: [PATCH] Port print arguments -q/-a/-S from main to restructuring. --- chatmastermind/commands/print.py | 10 +++++++++- chatmastermind/main.py | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/chatmastermind/commands/print.py b/chatmastermind/commands/print.py index 51e76f8..3d2b990 100644 --- a/chatmastermind/commands/print.py +++ b/chatmastermind/commands/print.py @@ -13,7 +13,15 @@ def print_cmd(args: argparse.Namespace, config: Config) -> None: try: message = Message.from_file(fname) if message: - print(message.to_str(source_code_only=args.source_code_only)) + if args.question: + print(message.question) + elif args.answer: + print(message.answer) + elif message.answer and args.only_source_code: + for code in message.answer.source_code(): + print(code) + else: + print(message.to_str()) except MessageError: print(f"File is not a valid message: {args.file}") sys.exit(1) diff --git a/chatmastermind/main.py b/chatmastermind/main.py index f7163ab..eadb095 100755 --- a/chatmastermind/main.py +++ b/chatmastermind/main.py @@ -113,8 +113,10 @@ def create_parser() -> argparse.ArgumentParser: aliases=['p']) print_cmd_parser.set_defaults(func=print_cmd) print_cmd_parser.add_argument('-f', '--file', help='File to print', required=True) - print_cmd_parser.add_argument('-S', '--source-code-only', help='Print source code only (from the answer, if available)', - action='store_true') + print_cmd_modes = print_cmd_parser.add_mutually_exclusive_group() + print_cmd_modes.add_argument('-q', '--question', help='Print only question', action='store_true') + print_cmd_modes.add_argument('-a', '--answer', help='Print only answer', action='store_true') + print_cmd_modes.add_argument('-S', '--only-source-code', help='Print only source code', action='store_true') argcomplete.autocomplete(parser) return parser