"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("./index");
var path_1 = require("path");
var pargv_1 = require("pargv");
var mustrConfig;
var pargv = new pargv_1.Pargv();
var chalk = new pargv_1.Chalk();
var mustrPath = path_1.resolve(process.cwd(), 'mustr.json');
// Try to load the mustr.json config if exists.
try {
    mustrConfig = require(mustrPath);
}
catch (ex) {
    mustrConfig = {};
}
// Create Mustr instance.
var mu = new index_1.Mustr(mustrConfig);
// Just add some spacing.
console.log();
// Handler for help.
function help() {
    var padBtm = [0, 0, 1, 0];
    var msg = '- See additional required/optional arguments for each command below. -\n';
    pargv
        .logo('Mustr', 'cyan')
        .ui(95)
        .join(chalk.magenta('Usage:'), 'mu', chalk.cyan('<cmd>'), '\n')
        .div({ text: chalk.bgBlue.white(msg) })
        .div({ text: chalk.cyan('help, h'), width: 35, padding: padBtm }, { text: chalk.gray('displays help and usage information.'), width: 40, padding: padBtm })
        .div({ text: chalk.cyan('init, i'), width: 35, padding: padBtm }, { text: chalk.gray('initialize the application for use with Mustr.'), width: 40, padding: padBtm })
        .div({ text: chalk.cyan('generate, g') + " " + chalk.white('<template>') + " " + chalk.magenta('<name>'), width: 35, padding: padBtm }, { text: chalk.gray('generates and renders a template.'), width: 40, padding: padBtm })
        .div({ text: chalk.white('<template>'), width: 35, padding: [0, 2, 0, 2] }, { text: chalk.gray('template to generate and compile.'), width: 40 }, { text: chalk.red('[required]'), align: 'right' })
        .div({ text: chalk.white('<name>'), width: 35, padding: [0, 2, 0, 2] }, { text: chalk.gray('output name for template'), width: 40 }, { text: chalk.red('[required]'), align: 'right' })
        .show();
}
// Handler for initializing.
function init() {
    mu.init(pargv.f);
}
// Handler for generating templates.
function generate() {
    if (!mustrConfig || !mustrConfig.configDir)
        mu.log.warn('invalid or missing Mustr config, do you need to call mu init?').exit();
    // Ensure config/templates loaded.
    mu.load();
    var name = pargv.getCmd(0);
    var output = pargv.getCmd(1);
    var options = pargv.getFlags();
    if (!name || !output)
        mu.log.error('cannot generate template using name or output of undefined.').exit();
    // Generate the template.
    mu.render(name, output, options);
}
// Bind CLI methods.
pargv
    .action('help', 'h', help)
    .action('init', 'i', init)
    .action('generate', 'g', generate)
    .action('*', function () {
    mu.log
        .warn('no command selected, did you mean to call "mu help"?')
        .write()
        .exit();
})
    .parse();
//# sourceMappingURL=cli.js.map