All files / src/commands/published-config published-config.command.js

50% Statements 20/40
100% Branches 1/1
0% Functions 0/1
50% Lines 20/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x                                         193x 193x  
import { getAllExposedEnvVars } from '@clevercloud/client/esm/api/v2/application.js';
import { toNameEqualsValueString } from '@clevercloud/client/esm/utils/env-vars.js';
import { defineCommand } from '../../lib/define-command.js';
import { Logger } from '../../logger.js';
import * as Application from '../../models/application.js';
import { sendToApi } from '../../models/send-to-api.js';
import { aliasOption, appIdOrNameOption, envFormatOption } from '../global.options.js';
 
export const publishedConfigCommand = defineCommand({
  description: 'Manage the configuration made available to other applications by this application',
  since: '0.5.0',
  options: {
    alias: aliasOption,
    app: appIdOrNameOption,
    format: envFormatOption,
  },
  args: [],
  async handler(options) {
    const { alias, app: appIdOrName, format } = options;
    const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);

    const publishedConfigs = await getAllExposedEnvVars({ id: ownerId, appId }).then(sendToApi);
    const pairs = Object.entries(publishedConfigs).map(([name, value]) => ({ name, value }));

    switch (format) {
      case 'json': {
        Logger.printJson(pairs);
        break;
      }
      case 'shell':
        Logger.println(toNameEqualsValueString(pairs, { addExports: true }));
        break;
      case 'human':
      default: {
        Logger.println('# Published configs');
        Logger.println(toNameEqualsValueString(pairs, { addExports: false }));
      }
    }
  },
});