import {
  inquirer_default
} from "./chunk-TCWYVU4U.js";
import {
  FragmentCommand,
  require_lib
} from "./chunk-XECLOG6B.js";
import {
  require_source
} from "./chunk-M5OAS5QZ.js";
import {
  __toESM,
  init_cjs_shims
} from "./chunk-7GH3YGSC.js";

// src/commands/update.ts
init_cjs_shims();
var import_core = __toESM(require_lib(), 1);
var import_chalk = __toESM(require_source(), 1);
var Update = class _Update extends FragmentCommand {
  static {
    this.description = "Update the FRAGMENT CLI";
  }
  static {
    this.examples = ["<%= config.bin %> <%= command.id %>"];
  }
  static {
    this.flags = {
      yes: import_core.Flags.boolean({ char: "y" }),
      "dry-run": import_core.Flags.boolean({ required: false, default: false })
    };
  }
  async run() {
    const { flags } = await this.parse(_Update);
    let shouldUpdate = flags.yes;
    const { outOfDate, latestRelease } = await this.outOfDate();
    if (!outOfDate) {
      this.log("Already up-to-date.");
      return;
    }
    if (!flags.yes) {
      ({ shouldUpdate } = await inquirer_default.prompt([
        {
          type: "confirm",
          name: "shouldUpdate",
          message: `The latest version is ${import_chalk.default.cyan(
            latestRelease
          )}. Your version: ${import_chalk.default.yellow(
            this.config.version
          )}.
Would you like to update the FRAGMENT CLI? (y/n)`,
          default: false
        }
      ]));
    }
    if (shouldUpdate) {
      await this.updateFragmentCli({ dryRun: flags["dry-run"] });
    } else {
      this.log("Not updating.");
      return;
    }
  }
};

export {
  Update
};
