"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander = require("commander");
const create_1 = require("../Api/create");
const WizError_1 = require("../modules/WizError");
const ensureAuth_1 = require("./utils/ensureAuth");
const logger_1 = require("./utils/logger");
const validateMonorepo_1 = require("./utils/validateMonorepo");
commander
    .name('wiz create layout')
    .description('Archive an email layout')
    .option('--from <layoutName...>', 'Archive the email layout from <layout-name>')
    .option('--name <archiveName>', 'Set the archive name')
    .option('--target <targetClmName>', 'Set the target system. This updates settings.json')
    .option('--theme <themeName>', 'Set the email theme. This updates settings.json')
    .option('--scheme <schemeName>', 'Set the email color scheme. This updates settings.json')
    .option('--from-all', 'Create an email for every layout available')
    .option('--no-archive', 'Save email project locally without archiving')
    .parse(process.argv);
const opts = commander.opts();
createLayout()
    .catch(logger_1.handleError)
    .finally(logger_1.closeLogger);
function createLayout() {
    return __awaiter(this, void 0, void 0, function* () {
        validateArgs(opts);
        yield (0, ensureAuth_1.default)();
        const baseDir = process.cwd();
        const action = yield (0, create_1.createAction)(baseDir);
        return action(baseDir, Object.assign({ command: 'layout' }, opts));
    });
}
function validateArgs(options) {
    if (!(0, validateMonorepo_1.areWorkspacesPassed)(options)) {
        throw new WizError_1.WizError('OPTION_NOT_SPECIFIED', '--from <layoutName...>');
    }
    (0, validateMonorepo_1.validateNameOption)(options);
}
//# sourceMappingURL=wiz-create-layout.js.map