Merge pull request #51 from sedrubal/feature_use-argparse-mutually_exclusive_group

Use argparse mutually_exclusive_group for --config-file and --config-data
pull/50/merge
Adrien Vergé 8 years ago committed by GitHub
commit db116eaaaf

@ -145,8 +145,11 @@ class CommandLineTestCase(unittest.TestCase):
out, err = sys.stdout.getvalue(), sys.stderr.getvalue() out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '') self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^Options --config-file and ' self.assertRegexpMatches(
r'--config-data cannot be used') 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): def test_run_with_bad_config(self):
sys.stdout, sys.stderr = StringIO(), StringIO() sys.stdout, sys.stderr = StringIO(), StringIO()

@ -78,11 +78,13 @@ def run(argv=None):
description=APP_DESCRIPTION) description=APP_DESCRIPTION)
parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+', parser.add_argument('files', metavar='FILE_OR_DIR', nargs='+',
help='files to check') help='files to check')
parser.add_argument('-c', '--config-file', dest='config_file', config_group = parser.add_mutually_exclusive_group()
action='store', help='path to a custom configuration') config_group.add_argument('-c', '--config-file', dest='config_file',
parser.add_argument('-d', '--config-data', dest='config_data', action='store',
action='store', help='path to a custom configuration')
help='custom configuration (as YAML source)') config_group.add_argument('-d', '--config-data', dest='config_data',
action='store',
help='custom configuration (as YAML source)')
parser.add_argument('-f', '--format', parser.add_argument('-f', '--format',
choices=('parsable', 'standard'), default='standard', choices=('parsable', 'standard'), default='standard',
help='format for parsing output') help='format for parsing output')
@ -97,11 +99,6 @@ def run(argv=None):
args = parser.parse_args(argv) 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 # User-global config is supposed to be in ~/.config/yamllint/config
if 'XDG_CONFIG_HOME' in os.environ: if 'XDG_CONFIG_HOME' in os.environ:
user_global_config = os.path.join( user_global_config = os.path.join(

Loading…
Cancel
Save