diff --git a/tests/test_cli.py b/tests/test_cli.py index 8a5bab5..86cc75e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -145,8 +145,11 @@ class CommandLineTestCase(unittest.TestCase): out, err = sys.stdout.getvalue(), sys.stderr.getvalue() self.assertEqual(out, '') - self.assertRegexpMatches(err, r'^Options --config-file and ' - r'--config-data cannot be used') + self.assertRegexpMatches( + err.splitlines()[-1], + r'^yamllint: error: argument -d\/--config-data: ' + r'not allowed with argument -c\/--config-file$' + ) def test_run_with_bad_config(self): sys.stdout, sys.stderr = StringIO(), StringIO() diff --git a/yamllint/cli.py b/yamllint/cli.py index 1a22f73..f207b88 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -78,11 +78,13 @@ def run(argv=None): description=APP_DESCRIPTION) parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+', help='files to check') - parser.add_argument('-c', '--config-file', dest='config_file', - action='store', help='path to a custom configuration') - parser.add_argument('-d', '--config-data', dest='config_data', - action='store', - help='custom configuration (as YAML source)') + config_group = parser.add_mutually_exclusive_group() + config_group.add_argument('-c', '--config-file', dest='config_file', + action='store', + help='path to a custom configuration') + config_group.add_argument('-d', '--config-data', dest='config_data', + action='store', + help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', choices=('parsable', 'standard'), default='standard', help='format for parsing output') @@ -97,11 +99,6 @@ def run(argv=None): args = parser.parse_args(argv) - if args.config_file is not None and args.config_data is not None: - print('Options --config-file and --config-data cannot be used ' - 'simultaneously.', file=sys.stderr) - sys.exit(-1) - # User-global config is supposed to be in ~/.config/yamllint/config if 'XDG_CONFIG_HOME' in os.environ: user_global_config = os.path.join(