#!/usr/bin/env node

/*
* @Author: Manraj Singh
* @Date:   2016-07-10 20:00:15
* @Last Modified by:   Manraj Singh
* @Last Modified time: 2016-07-23 19:46:10
*/

'use strict';

const yargs = require('yargs');
const fs = require('fs');
const ora = require('ora');
const chalk = require('chalk');
const config = require('./config');
const path = require('path');

const getPath = (folderPath, name) => {
  return path.resolve(folderPath, name);
}

/**
 * Returns file extension of param
 * @param  {string} lang [Language name]
 * @return {string}      [Extension of param language]
 */
const getExtension = (lang) => {
  return '';
}

const generate = (folderPath, ques, lang) => {
  let files = [ques.toString() + getExtension(lang), 'input.txt', 'output.txt'];
  fs.mkdirSync(folderPath);
  for(let i = 0; i<files.length; i++) {
    fs.writeFileSync(getPath(folderPath, files[i]), '', 'utf8');
  }
}

const argv = yargs
  .usage('sudo $0 <command>')
  .command('gen', 'Generate boilerplate', (yargs) => {
    const argv = yargs
      .usage('Usage: $0 gen <options>')
      .demand(['q'])
      .alias('l', 'language').describe('l', 'Language. Change `config` for default')
      .alias('q', 'questions').describe('q', 'Number of questions')
      .example('sudo $0 gen') // To-do
      .argv;
    let { l, q } = argv;
    l = l == undefined ? config['lang'] : l;
    for(let i = 1; i <= q; i++) {
      let folderPath = getPath(process.cwd(), i.toString());
      generate(folderPath, i, l);
    }
  })
  .command('config', 'Change config file', (yargs) => {
  	const argv = yargs
      .usage('Usage: $0 config <options>')
      .example('$0') // To-do
      .argv;
    const questions = [{
      type: 'input',
      name: 'default_lang',
      message: 'Enter default language code <leave blank incase unchanged>'
    } , {
      type: 'input',
      name: 'questions',
      message: 'Enter default number of questions <Leave blank incase unchanged>'
    }];
    inquirer.prompt(questions).then((answers) => {

    });
  })
  .help('h')
  .alias('h', 'help')
  .argv;

@@ -146,16 +146,16 @@
 -23 
-19:46:10
+20:34:19
 %0A*/%0A
@@ -1106,20 +1106,16 @@
 ', 'lang
-uage
 ').descr
@@ -1187,21 +1187,16 @@
 ', 'ques
-tions
 ').descr
@@ -1489,16 +1489,328 @@
  %7D%0A  %7D)%0A
+  .command('add', 'Add default template', (yargs) =%3E %7B%0A    const argv = yargs%0A      .usage('Usage: $0 add %3Coptions%3E')%0A      .demand(%5B't', 'l'%5D)%0A      .alias('t', 'template').describe('t', 'Path to the template')%0A      .alias('l', 'lang').describe('q', 'Language')%0A      .example('$0') // To-do%0A      .argv;%0A  %7D)%0A
   .comma
@@ -1863,9 +1863,10 @@
 %7B%0A  
-%09
+  
 cons
@@ -1910,26 +1910,16 @@
 0 config
- %3Coptions%3E
 ')%0A     
@@ -2075,17 +2075,17 @@
 e code %3C
-l
+L
 eave bla
@@ -2081,32 +2081,33 @@
  %3CLeave blank in
+ 
 case unchanged%3E'
@@ -2228,16 +2228,17 @@
 blank in
+ 
 case unc

Add template option