'use strict';

var minimist      = require('minimist'),
    fixmeToIssue  = require('./index.js'),
    pkg           = require('../package');

function help() {
  return '\
Usage:\n\
\n\
  fixme-to-issue [options] [file|glob ...]\n\
\n\
Options:\n\
\n\
  -h, --help                 output usage information\n\
  -v, --version              output version\n\
  -p, --path                 path to scan (default: process.cwd())\n\
  -i, --ignored_directories  glob patterns for directories to ignore (default: node_modules/**, .git/**, .hg/**)\n\
  -e, --file_encoding        file encoding to be scanned (default: utf8)\n\
  -l, --line_length_limit    number of max characters a line (default: 1000)\n\
  -s, --skip                 list of checks to skip (default: none)\n\
\n\
Examples:\n\
\n\
  By default:\n\
\n\
    fixme\n\
\n\
  Some ignored directories and some including files:\n\
\n\
    fixme -i \'node_modules/**\' -i \'.git/**\' -i \'build/**\' \'src/**/*.js\' \'test/*\' \n\
';
}

var argv = minimist(process.argv.slice(2));

if (argv.version || argv.v) {
  console.log(pkg.version);
  process.exit();
}

if (argv.help || argv.h) {
  console.log(help());
  process.exit();
}

var options = {};

var path = argv.path || argv.p;
if (path) {
  options.path = path;
}

var ignored_directories = argv.ignored_directories || argv.i;
if (typeof ignored_directories === 'string') {
  ignored_directories = [ignored_directories];
}
if (ignored_directories) {
  options.ignored_directories = ignored_directories;
}

var file_patterns = argv._;
if (file_patterns.length > 0) {
  options.file_patterns = file_patterns;
}

var file_encoding = argv.file_encoding || argv.e;
if (file_encoding) {
  options.file_encoding = file_encoding;
}

var line_length_limit = argv.line_length_limit || argv.l;
if (line_length_limit) {
  options.line_length_limit = line_length_limit;
}

var skip = argv.skip || argv.s;
if (typeof skip === 'string') {
  skip = [skip];
}
if (skip) {
  options.skip = skip;
}

var username = argv.username || argv.u;
if (username) {
  options.username = username;
}

var password = argv.password || argv.p;
if (password) {
  options.password = password;
}

// Custom labels
var lables = argv.lables || argv.l;
if (lables) {
  options.lables = JSON.parse(lables);
}

// Set prefix
var prefix = argv.prefix || argv.prefix;
options.prefix = prefix || '[Issue Bot]';

fixmeToIssue(options);

'use strict';

var minimist      = require('minimist'),
    fixmeToIssue  = require('./index.js'),
    pkg           = require('../package'),
    fixmeOptions  - require('../.fixme-to-issue');

function help() {
  return '\
Usage:\n\
\n\
  fixme-to-issue [options] [file|glob ...]\n\
\n\
Options:\n\
\n\
  -h, --help                 output usage information\n\
  -v, --version              output version\n\
  -p, --path                 path to scan (default: process.cwd())\n\
  -i, --ignored_directories  glob patterns for directories to ignore (default: node_modules/**, .git/**, .hg/**)\n\
  -e, --file_encoding        file encoding to be scanned (default: utf8)\n\
  -l, --line_length_limit    number of max characters a line (default: 1000)\n\
  -s, --skip                 list of checks to skip (default: none)\n\
\n\
Examples:\n\
\n\
  By default:\n\
\n\
    fixme\n\
\n\
  Some ignored directories and some including files:\n\
\n\
    fixme -i \'node_modules/**\' -i \'.git/**\' -i \'build/**\' \'src/**/*.js\' \'test/*\' \n\
';
}

var argv = minimist(process.argv.slice(2));

if (argv.version || argv.v) {
  console.log(pkg.version);
  process.exit();
}

if (argv.help || argv.h) {
  console.log(help());
  process.exit();
}

var options = {};

var path = argv.path || argv.p;
if (path) {
  options.path = path;
}

var ignored_directories = argv.ignored_directories || argv.i;
if (typeof ignored_directories === 'string') {
  ignored_directories = [ignored_directories];
}
if (ignored_directories) {
  options.ignored_directories = ignored_directories;
}

var file_patterns = argv._;
if (file_patterns.length > 0) {
  options.file_patterns = file_patterns;
}

var file_encoding = argv.file_encoding || argv.e;
if (file_encoding) {
  options.file_encoding = file_encoding;
}

var line_length_limit = argv.line_length_limit || argv.l;
if (line_length_limit) {
  options.line_length_limit = line_length_limit;
}

var skip = argv.skip || argv.s;
if (typeof skip === 'string') {
  skip = [skip];
}
if (skip) {
  options.skip = skip;
}

var username = argv.username || argv.u;
if (username) {
  options.username = username;
}

var password = argv.password || argv.p;
if (password) {
  options.password = password;
}

// Custom labels
var lables = argv.lables || argv.l;
if (lables) {
  options.lables = JSON.parse(lables);
}

// Set prefix
var prefix = argv.prefix || argv.prefix;
options.prefix = prefix || '[Issue Bot]';

fixmeToIssue(options);

refactor message checks