All files / src/commands/config config.set.command.js

73.68% Statements 28/38
100% Branches 1/1
0% Functions 0/1
73.68% Lines 28/38

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 39193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x                     193x 193x  
import { z } from 'zod';
import { defineArgument } from '../../lib/define-argument.js';
import { defineCommand } from '../../lib/define-command.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import * as Application from '../../models/application.js';
import * as ApplicationConfiguration from '../../models/application_configuration.js';
import { aliasOption, appIdOrNameOption } from '../global.options.js';
import { configurationNameArg } from './config.args.js';
 
export const configSetCommand = defineCommand({
  description: 'Edit one configuration setting',
  since: '2.5.0',
  options: {
    alias: aliasOption,
    app: appIdOrNameOption,
  },
  args: [
    configurationNameArg,
    defineArgument({
      schema: z.string(),
      description: 'The new value of the configuration',
      placeholder: 'configuration-value',
    }),
  ],
  async handler(options, configurationName, configurationValue) {
    const { alias, app: appIdOrName } = options;
    const { ownerId, appId } = await Application.resolveId(appIdOrName, alias);
    const appConfig = ApplicationConfiguration.getById(configurationName);
    const newOptions = {
      [appConfig.name]: ApplicationConfiguration.parse(appConfig, configurationValue),
    };
    const app = await Application.updateOptions(ownerId, appId, newOptions);
    Logger.printSuccess(
      `Config ${styleText('green', appConfig.id)} successfully updated to ${styleText('green', ApplicationConfiguration.formatValue(appConfig, app[appConfig.name]).toString())}!`,
    );
  },
});