mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(commands): share cleanup plan resolver
This commit is contained in:
25
src/commands/cleanup-plan.ts
Normal file
25
src/commands/cleanup-plan.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
loadConfig,
|
||||
resolveConfigPath,
|
||||
resolveOAuthDir,
|
||||
resolveStateDir,
|
||||
} from "../config/config.js";
|
||||
import { buildCleanupPlan } from "./cleanup-utils.js";
|
||||
|
||||
export function resolveCleanupPlanFromDisk(): {
|
||||
cfg: OpenClawConfig;
|
||||
stateDir: string;
|
||||
configPath: string;
|
||||
oauthDir: string;
|
||||
configInsideState: boolean;
|
||||
oauthInsideState: boolean;
|
||||
workspaceDirs: string[];
|
||||
} {
|
||||
const cfg = loadConfig();
|
||||
const stateDir = resolveStateDir();
|
||||
const configPath = resolveConfigPath();
|
||||
const oauthDir = resolveOAuthDir();
|
||||
const plan = buildCleanupPlan({ cfg, stateDir, configPath, oauthDir });
|
||||
return { cfg, stateDir, configPath, oauthDir, ...plan };
|
||||
}
|
||||
@@ -1,16 +1,11 @@
|
||||
import { cancel, confirm, isCancel, select } from "@clack/prompts";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import {
|
||||
isNixMode,
|
||||
loadConfig,
|
||||
resolveConfigPath,
|
||||
resolveOAuthDir,
|
||||
resolveStateDir,
|
||||
} from "../config/config.js";
|
||||
import { isNixMode } from "../config/config.js";
|
||||
import { resolveGatewayService } from "../daemon/service.js";
|
||||
import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js";
|
||||
import { buildCleanupPlan, listAgentSessionDirs, removePath } from "./cleanup-utils.js";
|
||||
import { resolveCleanupPlanFromDisk } from "./cleanup-plan.js";
|
||||
import { listAgentSessionDirs, removePath } from "./cleanup-utils.js";
|
||||
|
||||
export type ResetScope = "config" | "config+creds+sessions" | "full";
|
||||
|
||||
@@ -114,16 +109,8 @@ export async function resetCommand(runtime: RuntimeEnv, opts: ResetOptions) {
|
||||
}
|
||||
|
||||
const dryRun = Boolean(opts.dryRun);
|
||||
const cfg = loadConfig();
|
||||
const stateDir = resolveStateDir();
|
||||
const configPath = resolveConfigPath();
|
||||
const oauthDir = resolveOAuthDir();
|
||||
const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({
|
||||
cfg,
|
||||
stateDir,
|
||||
configPath,
|
||||
oauthDir,
|
||||
});
|
||||
const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } =
|
||||
resolveCleanupPlanFromDisk();
|
||||
|
||||
if (scope !== "config") {
|
||||
if (dryRun) {
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import { cancel, confirm, isCancel, multiselect } from "@clack/prompts";
|
||||
import path from "node:path";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
isNixMode,
|
||||
loadConfig,
|
||||
resolveConfigPath,
|
||||
resolveOAuthDir,
|
||||
resolveStateDir,
|
||||
} from "../config/config.js";
|
||||
import { isNixMode } from "../config/config.js";
|
||||
import { resolveGatewayService } from "../daemon/service.js";
|
||||
import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js";
|
||||
import { resolveHomeDir } from "../utils.js";
|
||||
import { buildCleanupPlan, removePath } from "./cleanup-utils.js";
|
||||
import { resolveCleanupPlanFromDisk } from "./cleanup-plan.js";
|
||||
import { removePath } from "./cleanup-utils.js";
|
||||
|
||||
type UninstallScope = "service" | "state" | "workspace" | "app";
|
||||
|
||||
@@ -157,16 +152,8 @@ export async function uninstallCommand(runtime: RuntimeEnv, opts: UninstallOptio
|
||||
}
|
||||
|
||||
const dryRun = Boolean(opts.dryRun);
|
||||
const cfg = loadConfig();
|
||||
const stateDir = resolveStateDir();
|
||||
const configPath = resolveConfigPath();
|
||||
const oauthDir = resolveOAuthDir();
|
||||
const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({
|
||||
cfg,
|
||||
stateDir,
|
||||
configPath,
|
||||
oauthDir,
|
||||
});
|
||||
const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } =
|
||||
resolveCleanupPlanFromDisk();
|
||||
|
||||
if (scopes.has("service")) {
|
||||
if (dryRun) {
|
||||
|
||||
Reference in New Issue
Block a user