"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const codiac_relay_contracts_1 = require("@codiac.io/codiac-relay-contracts");
const command_base_tenantless_1 = require("../../command-base-tenantless");
class PkgAdd extends command_base_tenantless_1.CommandBaseTenantless {
    run() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.bootstrap();
            const { args, flags } = yield this.parse(PkgAdd);
            //let pkgName: string = args.pkgName;
            // TODO:  Look for an existing package file
            //        and prompt for it if a) they didnt give one,
            //        and b) it's not already a package export for this project.
            // TODO:  If the source file doesnt exist, we should create one
            //        (does that mean initialize npm?  What if its already initialized and we're adding a NEW package to the same project?)
            let registryUrl = flags.registryUrl || codiac_relay_contracts_1.PackageExport.DEFAULT_REMOTE_REGISTRY_URL;
            let target = new codiac_relay_contracts_1.RegistryTarget(flags.environment || codiac_relay_contracts_1.ImageExport.DEFAULT_ENVIRONMENT_NAME, registryUrl, flags.username, flags.password);
            let result = yield this._ops.declarePackageExport(this._projCfg, target, args.definitionFile);
            if (result.package && result.name) {
                this._ui.userMessage(JSON.stringify(result.package, undefined, '  '));
                this._ui.userMessage(`Registered package export [${this._styler.colorGood(result.name)}] as [${this._styler.colorGood(result.package.definitionFile)}] (${result.operation}).`);
            }
        });
    }
}
exports.default = PkgAdd;
PkgAdd.description = 'Configures a package to be built and published by the project.';
PkgAdd.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    // definitionFile: flags.string({char: 'f', required: false, description: 'Path and filename of the package definition file, relative to the codiac project root, (eg: "./package.json")'}),
    registryUrl: core_1.Flags.string({ char: 'r', required: false, description: 'Address of the registry to which the package will be published (without protocol prefix), eg: "yourpackages.azurecr.io".  NOTE: This registry will be used by the "codiac publish" command, whereas when running in "local" mode, packages will instead be registered to the built-in package registry on the local machine.  NOTE:  This url shall define the default publishing target, for use when publishing for any environment, unless otherwise specified.' }),
    environment: core_1.Flags.string({ char: 'e', required: false, description: '(optional) Declaration that this registry shall be the target when publishing to the given environment.' }),
    username: core_1.Flags.string({ char: 'u', required: false, description: '(optional) Login credential for the given registry.  WARNING!! these username/password credentials will be stored in the codiac config file in this project, and therefore configuring username and password in this manner is not recommended!' }),
    password: core_1.Flags.string({ char: 's', required: false, description: '(optional) Password credential for the given registry.  WARNING!! these username/password credentials will be stored in the codiac config file in this project, and therefore configuring username and password in this manner is not recommended!' })
};
// static args = [{name: 'pkgName', required: true, description: 'package name including, scope prefix. eg:  "your-company/your-pkg"'}]
// static args = [{name: 'pkgName', required: false, description: 'package name including, scope prefix. eg:  "@your-company/your-pkg"'}]
PkgAdd.args = {
    definitionFile: core_1.Args.string({ required: false, description: 'Path and filename of the package definition file, relative to the codiac project root, (eg: "./package.json")' })
};
//# sourceMappingURL=add.js.map