cli: read optional config from YAMLLINT_CONFIG

This is a "minor" abi break since empty configs are
disregarded instead of failing.

Fixes: https://github.com/adrienverge/yamllint/issues/107
pull/119/head
Johan Bergström 7 years ago
parent e4e99f0aba
commit e52c1acd2a

@ -165,7 +165,19 @@ class CommandLineTestCase(unittest.TestCase):
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^invalid config: not a dict')
self.assertRegexpMatches(err, r'No such file or directory')
def test_run_with_environment_variable(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
rules = '{extends: default, rules: {document-start: {present: false}}}'
with self.assertRaises(SystemExit) as ctx:
os.environ['YAMLLINT_CONFIG'] = rules
cli.run((os.path.join(self.wd, 'warn.yaml'), ))
self.assertEqual(ctx.exception.code, 0)
out = sys.stdout.getvalue()
self.assertEqual(out, '')
del os.environ['YAMLLINT_CONFIG']
def test_run_with_config_file(self):
with open(os.path.join(self.wd, 'config'), 'w') as f:

@ -94,6 +94,7 @@ def run(argv=None):
help='path to a custom configuration')
config_group.add_argument('-d', '--config-data', dest='config_data',
action='store',
default=os.environ.get('YAMLLINT_CONFIG', ''),
help='custom configuration (as YAML source)')
parser.add_argument('-f', '--format',
choices=('parsable', 'standard'), default='standard',
@ -117,8 +118,8 @@ def run(argv=None):
user_global_config = os.path.expanduser('~/.config/yamllint/config')
try:
if args.config_data is not None:
if args.config_data != '' and ':' not in args.config_data:
if args.config_data != '':
if ':' not in args.config_data:
args.config_data = 'extends: ' + args.config_data
conf = YamlLintConfig(content=args.config_data)
elif args.config_file is not None:

Loading…
Cancel
Save