mirror of
https://github.com/adrienverge/yamllint.git
synced 2025-02-25 18:55:20 -06:00
Merge pull request #51 from sedrubal/feature_use-argparse-mutually_exclusive_group
Use argparse mutually_exclusive_group for --config-file and --config-data
This commit is contained in:
commit
db116eaaaf
@ -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()
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user