From 664241d9be8042f0b26515f6ffadc53f3b6e30ca Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Wed, 28 Apr 2021 18:43:22 +0200 Subject: main: Make --joined and --no-joined mutually exclusive Sadly we can not yet rely on BooleanOptionalAction, since that was only added in Python 3.9. Also remove the FIXME note, it seems that boolean options like this trigger a standard default setting with argparse. --- quarg/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/quarg/main.py b/quarg/main.py index 410306a..cbd5177 100644 --- a/quarg/main.py +++ b/quarg/main.py @@ -14,7 +14,6 @@ from quarg.quassel.formatter import format_from from quarg.utils import errx # TODO Make --after/--before and --around mutually exclusive -# FIXME why need default=None for --joined/--no-joined? # pylint: disable=line-too-long cli = argparse.ArgumentParser() @@ -29,11 +28,13 @@ cli.add_argument('-u', action='append', dest='user', help='match messages receiv cli.add_argument('-t', action=actions.ParseMessageType, dest='msgtype', help='match messages of this message type') cli.add_argument('-f', action=actions.ParseMessageFlag, dest='msgflag', help='match messages with this flag') cli.add_argument('-p', action='append', dest='prefix', help='match nicks with this prefix') -cli.add_argument('--joined', default=None, action='store_true', dest='joined', help='match messages sent to channels which are currently joined') -cli.add_argument('--no-joined', default=None, action='store_false', dest='joined', help='match messages sent to channels which are not currently joined') cli.add_argument('--after', action=actions.ParseDate, metavar='DATE', help='match messages sent after this date') cli.add_argument('--before', action=actions.ParseDate, metavar='DATE', help='match messages sent before this date') cli.add_argument('--around', action=actions.ParseAround, metavar='DATE', help='match messages sent within 12 hours of this date') + +joined_group = cli.add_mutually_exclusive_group() +joined_group.add_argument('--joined', default=None, action='store_true', dest='joined', help='match messages sent to channels which are currently joined') +joined_group.add_argument('--no-joined', default=None, action='store_false', dest='joined', help='match messages sent to channels which are not currently joined') # pylint: enable=line-too-long Session = sessionmaker() -- cgit v1.2.3-2-gb3c3