All files / src/commands/config-provider config-provider.list.command.js

47.05% Statements 16/34
100% Branches 1/1
0% Functions 0/1
47.05% Lines 16/34

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 35193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x                                     193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { printItemsByOwner } from '../../lib/print-items-by-owner.js';
import { Logger } from '../../logger.js';
import { findAddonsByAddonProvider } from '../../models/ids-resolver.js';
import { humanJsonOutputFormatOption } from '../global.options.js';
 
export const configProviderListCommand = defineCommand({
  description: 'List configuration providers',
  since: '4.6.0',
  options: {
    format: humanJsonOutputFormatOption,
  },
  args: [],
  async handler(options) {
    const { format } = options;
    const deployed = await findAddonsByAddonProvider('config-provider');

    switch (format) {
      case 'json': {
        const providersPerOwner = Object.groupBy(deployed, (p) => p.ownerId);
        Logger.printJson(providersPerOwner);
        break;
      }
      case 'human':
      default:
        printItemsByOwner(deployed, {
          itemName: 'configuration provider',
          emptyCommand: 'clever addon create config-provider',
          getItemId: (p) => p.realId,
        });
        break;
    }
  },
});