question_cmd: tag options without a tag (e. g. '-t') now select ALL tags
This commit is contained in:
parent
6d085a6c80
commit
420d0695c4
@ -151,13 +151,34 @@ def repeat_messages(messages: list[Message], chat: ChatDB, args: argparse.Namesp
|
|||||||
make_request(ai, chat, message, args)
|
make_request(ai, chat, message, args)
|
||||||
|
|
||||||
|
|
||||||
|
def modify_tag_args(args: argparse.Namespace) -> None:
|
||||||
|
"""
|
||||||
|
Changes the semantics of the tags for this command:
|
||||||
|
* not tags specified -> no tags are selected
|
||||||
|
* empty tags specified -> 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
|
||||||
|
if args.exclude_tags is None:
|
||||||
|
args.exclude_tags = set()
|
||||||
|
elif len(args.exclude_tags) == 0:
|
||||||
|
args.exclude_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(),
|
modify_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)
|
||||||
|
|||||||
@ -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='+',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user