From d76a6cbb1832fb3337171edeb38e38b498ba4ef9 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 1 Aug 2019 08:14:21 -0700 Subject: [PATCH] Some arguments of mat2 are mutually exclusive --- mat2 | 31 +++++++++++++++++++------------ tests/test_climat2.py | 10 ++++++---- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/mat2 b/mat2 index f6f3af3..70712b8 100755 --- a/mat2 +++ b/mat2 @@ -46,13 +46,7 @@ def __check_file(filename: str, mode: int = os.R_OK) -> bool: def create_arg_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(description='Metadata anonymisation toolkit 2') - parser.add_argument('files', nargs='*', help='the files to process') - parser.add_argument('-v', '--version', action='version', - version='MAT2 %s' % __version__) - parser.add_argument('-l', '--list', action='store_true', - help='list all supported fileformats') - parser.add_argument('--check-dependencies', action='store_true', - help='check if MAT2 has all the dependencies it needs') + parser.add_argument('-V', '--verbose', action='store_true', help='show more verbose status information') parser.add_argument('--unknown-members', metavar='policy', default='abort', @@ -60,12 +54,25 @@ def create_arg_parser() -> argparse.ArgumentParser: 'files (policy should be one of: %s) [Default: abort]' % ', '.join(p.value for p in UnknownMemberPolicy)) + excl_group = parser.add_mutually_exclusive_group() + excl_group.add_argument('files', nargs='*', help='the files to process', + default=[]) + excl_group.add_argument('-v', '--version', action='version', + version='MAT2 %s' % __version__) + excl_group.add_argument('-l', '--list', action='store_true', default=False, + help='list all supported fileformats') + excl_group.add_argument('--check-dependencies', action='store_true', + default=False, + help='check if MAT2 has all the dependencies it ' + 'needs') + + excl_group = parser.add_mutually_exclusive_group() + excl_group.add_argument('-L', '--lightweight', action='store_true', + help='remove SOME metadata') + excl_group.add_argument('-s', '--show', action='store_true', + help='list harmful metadata detectable by MAT2 ' + 'without removing them') - info = parser.add_mutually_exclusive_group() - info.add_argument('-s', '--show', action='store_true', - help='list harmful metadata detectable by MAT2 without removing them') - info.add_argument('-L', '--lightweight', action='store_true', - help='remove SOME metadata') return parser diff --git a/tests/test_climat2.py b/tests/test_climat2.py index 4a46644..bbb9c06 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py @@ -20,16 +20,18 @@ class TestHelp(unittest.TestCase): def test_help(self): proc = subprocess.Popen(mat2_binary + ['--help'], stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]', + self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [-v] [-l]', stdout) - self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout) + self.assertIn(b'[--check-dependencies] [-L | -s]', stdout) + self.assertIn(b'[files [files ...]]', stdout) def test_no_arg(self): proc = subprocess.Popen(mat2_binary, stdout=subprocess.PIPE) stdout, _ = proc.communicate() - self.assertIn(b'usage: mat2 [-h] [-v] [-l] [--check-dependencies] [-V]', + self.assertIn(b'mat2 [-h] [-V] [--unknown-members policy] [-v] [-l]', stdout) - self.assertIn(b'[--unknown-members policy] [-s | -L]', stdout) + self.assertIn(b'[--check-dependencies] [-L | -s]', stdout) + self.assertIn(b'[files [files ...]]', stdout) class TestVersion(unittest.TestCase):