import { handleCache } from "../../tools/cache.js";
import { createLogger } from "../../logger.js";
const log = createLogger("repl");
async function executeCache(args) {
  try {
    const subcommand = args.positional[0];
    let input;
    if (subcommand === "stats" || !subcommand && !args.flags.query) {
      input = { stats: true };
    } else if (subcommand === "clear") {
      input = {
        clear: true,
        query: args.flags.query,
        url_pattern: args.flags["url-pattern"],
        since: args.flags.since
      };
    } else if (subcommand === "search") {
      const query = args.positional.slice(1).join(" ").trim() || args.flags.query;
      input = {
        query,
        url_pattern: args.flags["url-pattern"],
        since: args.flags.since
      };
    } else {
      const query = args.positional.join(" ").trim();
      input = {
        query: query || args.flags.query,
        url_pattern: args.flags["url-pattern"],
        since: args.flags.since
      };
    }
    log.debug("executing cache command", { subcommand, flags: args.flags });
    return await handleCache(input);
  } catch (err) {
    const msg = err instanceof Error ? err.message : String(err);
    log.error("cache command failed", { error: msg });
    return { error: msg };
  }
}
export {
  executeCache
};
//# sourceMappingURL=cache.js.map