Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ef1339cc0 | |||
| ed567afbea | |||
| 6e447018d5 |
@@ -18,8 +18,7 @@ default_config = '.config.yaml'
|
||||
|
||||
|
||||
def tags_completer(prefix: str, parsed_args: Any, **kwargs: Any) -> list[str]:
|
||||
with open(parsed_args.config, 'r') as f:
|
||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||
config = Config.from_file(parsed_args.config)
|
||||
return get_tags_unique(config, prefix)
|
||||
|
||||
|
||||
@@ -126,6 +125,10 @@ def print_cmd(args: argparse.Namespace, config: Config) -> None:
|
||||
sys.exit(1)
|
||||
if args.only_source_code:
|
||||
display_source_code(data['answer'])
|
||||
elif args.answer:
|
||||
print(data['answer'].strip())
|
||||
elif args.question:
|
||||
print(data['question'].strip())
|
||||
else:
|
||||
print(dump_data(data).strip())
|
||||
|
||||
@@ -214,8 +217,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', '--only-source-code', help='Print only source code',
|
||||
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
|
||||
|
||||
@@ -55,9 +55,10 @@ def message_to_chat(message: dict[str, str],
|
||||
def display_source_code(content: str) -> None:
|
||||
try:
|
||||
content_start = content.index('```')
|
||||
content_start = content.index('\n', content_start) + 1
|
||||
content_end = content.rindex('```')
|
||||
if content_start + 3 < content_end:
|
||||
print(content[content_start + 3:content_end].strip())
|
||||
if content_start < content_end:
|
||||
print(content[content_start:content_end].strip())
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user