question_cmd: input tag options without a tag (e. g. '-t') now select ALL tags

This commit is contained in:
2023-09-22 07:51:05 +02:00
parent 33df84beaa
commit 80c5dcc801
2 changed files with 25 additions and 9 deletions
+22 -6
View File
@@ -118,14 +118,13 @@ def make_msg_args(msg: Message, args: argparse.Namespace) -> argparse.Namespace:
# use those from the original message # use those from the original message
if (args.AI is None if (args.AI is None
or args.model is None # noqa: W503 or args.model is None # noqa: W503
or args.output_tags is None # noqa: W503 or args.output_tags is None): # noqa: W503
or len(args.output_tags) == 0): # noqa: W503
msg_args = deepcopy(args) msg_args = deepcopy(args)
if args.AI is None and msg.ai is not None: if args.AI is None and msg.ai is not None:
msg_args.AI = msg.ai msg_args.AI = msg.ai
if args.model is None and msg.model is not None: if args.model is None and msg.model is not None:
msg_args.model = msg.model msg_args.model = msg.model
if (args.output_tags is None or len(args.output_tags) == 0) and msg.tags is not None: if args.output_tags is None and msg.tags is not None:
msg_args.output_tags = msg.tags msg_args.output_tags = msg.tags
return msg_args return msg_args
@@ -151,13 +150,30 @@ def repeat_messages(messages: list[Message], chat: ChatDB, args: argparse.Namesp
make_request(ai, chat, message, args) make_request(ai, chat, message, args)
def invert_input_tag_args(args: argparse.Namespace) -> None:
"""
Changes the semantics of the INPUT tags for this command:
* not tags specified on the CLI -> no tags are selected
* empty tags specified on the CLI -> all tags are selected
"""
if args.or_tags is None:
args.or_tags = set()
elif len(args.or_tags) == 0:
args.or_tags = None
if args.and_tags is None:
args.and_tags = set()
elif len(args.and_tags) == 0:
args.and_tags = None
def question_cmd(args: argparse.Namespace, config: Config) -> None: def question_cmd(args: argparse.Namespace, config: Config) -> None:
""" """
Handler for the 'question' command. Handler for the 'question' command.
""" """
mfilter = MessageFilter(tags_or=args.or_tags if args.or_tags is not None else set(), invert_input_tag_args(args)
tags_and=args.and_tags if args.and_tags is not None else set(), mfilter = MessageFilter(tags_or=args.or_tags,
tags_not=args.exclude_tags if args.exclude_tags is not None else set()) tags_and=args.and_tags,
tags_not=args.exclude_tags)
chat = ChatDB.from_dir(cache_path=Path(config.cache), chat = ChatDB.from_dir(cache_path=Path(config.cache),
db_path=Path(config.db), db_path=Path(config.db),
mfilter=mfilter) mfilter=mfilter)
+3 -3
View File
@@ -34,13 +34,13 @@ def create_parser() -> argparse.ArgumentParser:
# a parent parser for all commands that support tag selection # a parent parser for all commands that support tag selection
tag_parser = argparse.ArgumentParser(add_help=False) tag_parser = argparse.ArgumentParser(add_help=False)
tag_arg = tag_parser.add_argument('-t', '--or-tags', nargs='+', tag_arg = tag_parser.add_argument('-t', '--or-tags', nargs='*',
help='List of tags (one must match)', metavar='OTAGS') help='List of tags (one must match)', metavar='OTAGS')
tag_arg.completer = tags_completer # type: ignore tag_arg.completer = tags_completer # type: ignore
atag_arg = tag_parser.add_argument('-k', '--and-tags', nargs='+', atag_arg = tag_parser.add_argument('-k', '--and-tags', nargs='*',
help='List of tags (all must match)', metavar='ATAGS') help='List of tags (all must match)', metavar='ATAGS')
atag_arg.completer = tags_completer # type: ignore atag_arg.completer = tags_completer # type: ignore
etag_arg = tag_parser.add_argument('-x', '--exclude-tags', nargs='+', etag_arg = tag_parser.add_argument('-x', '--exclude-tags', nargs='*',
help='List of tags to exclude', metavar='XTAGS') help='List of tags to exclude', metavar='XTAGS')
etag_arg.completer = tags_completer # type: ignore etag_arg.completer = tags_completer # type: ignore
otag_arg = tag_parser.add_argument('-o', '--output-tags', nargs='+', otag_arg = tag_parser.add_argument('-o', '--output-tags', nargs='+',