#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var license_file_1 = require("./license-file");
function printusage() {
    console.log("openflow-cli [--months 3][--email email] domain");
    console.log("   --months - Set number of months, default 3");
    console.log("   --email - email to use in license");
    console.log("   domain - Generate ofid and create v2 license");
    console.log("Requires private key to be in ./config/private_key.pem");
}
var optionDefinitions = [
    { name: 'email', type: String },
    { name: 'months', type: Number },
    { name: 'domain', type: String, defaultOption: true }
];
var commandLineArgs = require('command-line-args');
var options = null;
try {
    options = commandLineArgs(optionDefinitions, { partial: true });
    var months = 3;
    if (!options.email && !options.domain) {
        throw new Error("Domain is mandatory");
    }
    if (!options.email)
        options.email = "";
    if (options.months) {
        months = parseInt(options.months);
    }
    if (options._unknown) {
        console.log("Unknown param " + options._unknown);
        process.exit();
    }
    if (!fs.existsSync('config/private_key.pem')) {
        console.log("no such file or directory, open config/private_key.pem");
        process.exit();
    }
    var data = {};
    var template = license_file_1.LicenseFile.template_v1;
    data.licenseVersion = 1;
    data.email = options.email;
    if (options.domain) {
        template = license_file_1.LicenseFile.template_v2;
        data.licenseVersion = 2;
        data.domain = options.domain;
    }
    var dt = new Date(new Date().toISOString());
    dt.setMonth(dt.getMonth() + months);
    data.expirationDate = dt.toISOString();
    var licenseFileContent = license_file_1.LicenseFile.generate({
        privateKeyPath: 'config/private_key.pem',
        template: template,
        data: data
    });
    console.log(Buffer.from(licenseFileContent).toString('base64'));
    // console.log("---------------------------------------------------");
    // console.log(licenseFileContent);
    process.exit();
}
catch (error) {
    console.error(error.message ? error.message : error);
    printusage();
    process.exit();
}
// node C:\code\openflow\dist\cli-lic.js --months 1 localhost.openiap.io
// openflow-lic --months 1 localhost.openiap.io | clip
//# sourceMappingURL=cli-lic.js.map