"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigGet = void 0;
const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
const command_1 = require("@heroku-cli/command");
const core_1 = require("@oclif/core");
const quote_1 = require("../../lib/config/quote");
class ConfigGet extends command_1.Command {
    async run() {
        const { argv, flags } = await this.parse(ConfigGet);
        const { body: config } = await this.heroku.get(`/apps/${flags.app}/config-vars`);
        if (flags.json) {
            const results = argv.map(key => {
                const exists = key in config;
                return {
                    key,
                    value: exists ? config[key] : null,
                };
            });
            if (results.length === 1) {
                heroku_cli_util_1.hux.styledJSON(results[0]);
            }
            else {
                heroku_cli_util_1.hux.styledJSON(results);
            }
        }
        else if (flags.shell) {
            for (const key of argv) {
                const v = config[key];
                this.log(`${key}=${(0, quote_1.quote)(v || '')}`);
            }
        }
        else {
            for (const key of argv) {
                const v = config[key];
                this.log(v || '');
            }
        }
    }
}
exports.ConfigGet = ConfigGet;
ConfigGet.args = {
    KEY: core_1.Args.string({ description: 'key name of the config var value', required: true }),
};
ConfigGet.description = 'display a single config value for an app';
ConfigGet.example = `$ heroku config:get RAILS_ENV
production`;
ConfigGet.flags = {
    app: command_1.flags.app({ required: true }),
    json: command_1.flags.boolean({ char: 'j', description: 'output in json format' }),
    remote: command_1.flags.remote(),
    shell: command_1.flags.boolean({ char: 's', description: 'output config vars in shell format' }),
};
ConfigGet.strict = false;
ConfigGet.usage = 'config:get KEY...';
