import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  loadProjectModel
} from "./chunk-KSFSFWUC.js";
import {
  createCommandTransaction
} from "./chunk-ZBFOAJ5H.js";
import {
  reportCommandStartEvent
} from "./chunk-HENH75UF.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-old/src/commands/run-command.ts
init_esm_shims();
import { cwd } from "node:process";
async function initServices({
  model,
  services,
  cliVersion,
  command
}) {
  const { metaSiteId } = model;
  const { biLogger, errorReporter, panorama } = services;
  const project = "Sites";
  errorReporter.setTag("project", project);
  errorReporter.setTag("project.site_id", metaSiteId);
  panorama.setDefaultClientData({ cliProject: project, cliSiteId: metaSiteId });
  biLogger.updateDefaults({
    flow: project,
    command: command.name(),
    cliVersion,
    _msid: metaSiteId
  });
}
async function runCommand(command, services, cliVersion, commandFn) {
  const model = await loadProjectModel(cwd());
  await initServices({ model, services, command, cliVersion });
  const commandStatus = reportCommandStartEvent({
    biLogger: services.biLogger,
    command,
    cliVersion,
    flow: "Sites"
  });
  const transaction = createCommandTransaction(services.panorama, command);
  try {
    transaction.start();
    await commandFn(model);
    transaction.finish();
    commandStatus.succeed();
  } catch (e) {
    commandStatus.failed(e);
    throw e;
  }
}

export {
  runCommand
};
//# sourceMappingURL=chunk-4THLGEJA.js.map