#!/usr/bin/env node

'use strict'

const resolve = require('path').resolve
const loadProject = require('../load-project.js')
const renderProject = require('../render-project.js')
const argv = require('minimist')(process.argv.slice(2))
const selectSyntax = require('./select-syntax.js')
const init = require('./init.js')
const path = require('path')
const installAirline = require('./install-airline.js')
const installLightline = require('./install-lightline.js')
const projectPath = resolve('.')

const updateNotifier = require('update-notifier')
const pkg = require('../../package.json')

updateNotifier({
  pkg,
  updateCheckInterval: 1000 * 60 * 60 * 24 // 1 day
}).notify()

const command = argv._[0]

if (!command || command === 'help') {
  showHelp()
} else if (command === 'render') {
  loadProject(projectPath, renderProject)
} else if (command === 'add-syntax') {
  selectSyntax(projectPath)
} else if (command === 'init') {
  init(path.resolve(argv._[1] || '.'), argv.y)
} else if (command === 'add-airline') {
  installAirline(projectPath)
} else if (command === 'add-lightline') {
  installLightline(projectPath)
} else if (command === 'version' || argv.v) {
  console.log(pkg.version)
} else {
  console.log('Command not found')
  showHelp()
}

function showHelp () {
  console.log(`
  Usage: estilo [command]

  Commands:

    init                initialize an estilo project in current folder
    render              render all the colorschemes and themes
    add-syntax          open dialog: add more syntax templates
    add-airline         open dialog: add a new Airline style
    add-lightline       open dialog: add a new Lightline style
    version             output version number
    help                show this help
`)
}


@@ -583,16 +583,480 @@
 json')%0A%0A
+const help = %60%0A  Usage: estilo %5Bcommand%5D%0A%0A  Commands:%0A%0A    init                initialize an estilo project in current folder%0A    render              render all the colorschemes and themes%0A    add-syntax          open dialog: add more syntax templates%0A    add-airline         open dialog: add a new Airline style%0A    add-lightline       open dialog: add a new Lightline style%0A    version             output version number%0A    help                show this help%0A%60%0A%0A
 updateNo
@@ -1203,25 +1203,32 @@
 p') %7B%0A  
-showH
+console.log(h
 elp
-(
 )%0A%7D else
@@ -1712,509 +1712,24 @@
 )%0A  
-showHelp()%0A%7D%0A%0Afunction showHelp () %7B%0A  console.log(%60%0A  Usage: estilo %5Bcommand%5D%0A%0A  Commands:%0A%0A    init                initialize an estilo project in current folder%0A    render              render all the colorschemes and themes%0A    add-syntax          open dialog: add more syntax templates%0A    add-airline         open dialog: add a new Airline style%0A    add-lightline       open dialog: add a new Lightline style%0A    version             output version number%0A    help                show this help%0A%60
+console.log(help
 )%0A%7D%0A
-%0A

store help in a literal string