Skip to content

Commit 2a36ddc

Browse files
committed
Refactor exclusive argument check using argparse's builtin functionality
1 parent fca0012 commit 2a36ddc

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

lib/fdiff/__main__.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def run(argv):
4545
parser.add_argument(
4646
"-l", "--lines", type=int, default=3, help="Number of context lines (default 3)"
4747
)
48-
parser.add_argument(
48+
filters = parser.add_mutually_exclusive_group()
49+
filters.add_argument(
4950
"--include",
5051
type=str,
5152
default=None,
5253
help="Comma separated list of tables to include",
5354
)
54-
parser.add_argument(
55+
filters.add_argument(
5556
"--exclude",
5657
type=str,
5758
default=None,
@@ -74,17 +75,6 @@ def run(argv):
7475
#
7576
# /////////////////////////////////////////////////////////
7677

77-
# ----------------------------------
78-
# Incompatible argument validations
79-
# ----------------------------------
80-
# --include and --exclude are mutually exclusive options
81-
if args.include and args.exclude:
82-
sys.stderr.write(
83-
f"[*] Error: --include and --exclude are mutually exclusive options. "
84-
f"Please use ONLY one of these options in your command.{os.linesep}"
85-
)
86-
sys.exit(1)
87-
8878
# -------------------------------
8979
# File path argument validations
9080
# -------------------------------

0 commit comments

Comments
 (0)