import { install } from "../api/install";
import { normalizeDsns } from "../internal/normalizeDsns";
import type { Args } from "../internal/parseArgs";

/**
 * Installs the library in the provided databases.
 */
export async function actionInstall(args: Args): Promise<boolean> {
  const dsns = await normalizeDsns(args["dsns"] || args["dsn"]);
  if (dsns.length === 0) {
    throw "Please provide --dsn or --dsns, DB DSNs to install the library to";
  }

  for (const dsn of dsns) {
    await install({
      dsn,
      schemaNameFmt: args["schema-name-fmt"],
    });
  }

  return true;
}
