#!/usr/bin/env node

const path = require('path');
const nconf = require('nconf');
const leprechaun = require('leprechaun');
const snakeCase = require('lodash.snakecase');
const glob = require('glob');
const yamlLint = require('./yaml-lint');

const options = {};

nconf.argv().env({
  match: /^yamllint/i
}).file({
  file: path.resolve(process.cwd(), '.yaml-lint.json')
});

[
  'schema',
  'ignore'
].forEach((key) => {
  const env = snakeCase(key);
  options[key] = nconf.get(key) || nconf.get('yamllint_' + env.toLowerCase()) || nconf.get('YAMLLINT' + env.toUpperCase());
});

const config = nconf.get();

let files = [];

(config._ || []).forEach((pattern) => {
  files = files.concat(glob.sync(pattern, {
    nocase: true,
    dot: true,
    ignore: config.ignore
  }));
});

if (files.length === 0) {

  leprechaun.error('YAML Lint failed.');
  leprechaun.error('No YAML files were found matching your selection.');
  process.exit(1);

} else {

  Promise.all(files.map((file) => yamlLint
    .lintFile(file, options)
    .catch((err) => {
      err.file = file;
      throw err;
    })
  )).then(() => {
    leprechaun.success('YAML Lint successful.');
  }).catch((error) => {
    leprechaun.error('YAML Lint failed for ' + error.file);
    leprechaun.error(error.message);
    process.exit(1);
  });

}

@@ -490,17 +490,17 @@
 onf.get(
-'
+%60
 yamllint
@@ -500,20 +500,18 @@
 amllint_
-' + 
+$%7B
 env.toLo
@@ -519,16 +519,18 @@
 erCase()
+%7D%60
 ) %7C%7C nco
@@ -540,17 +540,17 @@
 get(
-'
+%60
 YAMLLINT
 ' + 
@@ -545,20 +545,19 @@
 YAMLLINT
-' + 
+_$%7B
 env.toUp
@@ -565,16 +565,18 @@
 erCase()
+%7D%60
 );%0A%7D);%0A%0A
@@ -694,23 +694,52 @@
 ob.sync(
+path.resolve(process.cwd(), 
 pattern
+)
 , %7B%0A    
@@ -792,16 +792,36 @@
 g.ignore
+,%0A    absolute: true
 %0A  %7D));%0A
@@ -1241,33 +1241,33 @@
 eprechaun.error(
-'
+%60
 YAML Lint failed
@@ -1275,12 +1275,10 @@
 for 
-' + 
+$%7B
 erro
@@ -1283,16 +1283,18 @@
 ror.file
+%7D%60
 );%0A    l

Fix CLI support relative paths