export default async function main()

in util/config/configurator/configurator.ts [66:147]


export default async function main() {
  const options: { showhelp: { type: 'boolean' }, override: { type: 'boolean' } } = {
    showhelp: {
      type: 'boolean',
    },
    override: {
      type: 'boolean',
    },
  };
  const { values, positionals } = parseArgs({
    args: Bun.argv,
    options: options,
    strict: true,
    allowPositionals: true,

  });

  if (values.showhelp) {
    console.log(HelpMsg);
    return process.exit(0);
  }

  const override = values.override || false;

  // 1. Read input config json
  const readPosRes = readPositionalFile(positionals);
  if (!readPosRes.success) {
    cancel(readPosRes.message);
    return process.exit(1);
  }

  if (readPosRes.help) {
    console.log(readPosRes.help);
    return process.exit(0);
  }

  if (readPosRes.message) {
    console.warn(readPosRes.message);
  }

  // 2. Parse the json
  const jsonRes = await parsePositionalFile(readPosRes.jsonFilePath!);

  if (!jsonRes.success) {
    cancel(jsonRes.message);
    return process.exit(1);
  }

  const config = jsonRes.body;

  // 3. Validate the given config json
  if (!isInputConfigValid(config)) {
    cancel(BadConfigMsg);
    return process.exit(1);
  }

  // 4. Run OPS to get the available config data
  const { exitCode, stderr, stdout } = await $`${OPS} -config -d`.quiet();
  if (exitCode !== 0) {
    cancel(stderr.toString());
    return process.exit(1);
  }

  const opsCurrentConfig = stdout.toString();

  // 5. Remove the keys from config that are already in the opsConfig
  let missingData = config;
  if (!override) {
    missingData = findMissingConfig(config, opsCurrentConfig);
  }

  // 6. Ask the user for the missing data
  console.log();
  intro(color.inverse(" ops configurator "));

  await askMissingData(missingData, override);

  // 7. Save the data to the config?
  console.log();

  outro("You're all set!");
}