mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:01:25 +00: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 { cancel, confirm, isCancel, select } from "@clack/prompts";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import { formatCliCommand } from "../cli/command-format.js";
|
import { formatCliCommand } from "../cli/command-format.js";
|
||||||
import {
|
import { isNixMode } from "../config/config.js";
|
||||||
isNixMode,
|
|
||||||
loadConfig,
|
|
||||||
resolveConfigPath,
|
|
||||||
resolveOAuthDir,
|
|
||||||
resolveStateDir,
|
|
||||||
} from "../config/config.js";
|
|
||||||
import { resolveGatewayService } from "../daemon/service.js";
|
import { resolveGatewayService } from "../daemon/service.js";
|
||||||
import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.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";
|
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 dryRun = Boolean(opts.dryRun);
|
||||||
const cfg = loadConfig();
|
const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } =
|
||||||
const stateDir = resolveStateDir();
|
resolveCleanupPlanFromDisk();
|
||||||
const configPath = resolveConfigPath();
|
|
||||||
const oauthDir = resolveOAuthDir();
|
|
||||||
const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({
|
|
||||||
cfg,
|
|
||||||
stateDir,
|
|
||||||
configPath,
|
|
||||||
oauthDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (scope !== "config") {
|
if (scope !== "config") {
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
import { cancel, confirm, isCancel, multiselect } from "@clack/prompts";
|
import { cancel, confirm, isCancel, multiselect } from "@clack/prompts";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import {
|
import { isNixMode } from "../config/config.js";
|
||||||
isNixMode,
|
|
||||||
loadConfig,
|
|
||||||
resolveConfigPath,
|
|
||||||
resolveOAuthDir,
|
|
||||||
resolveStateDir,
|
|
||||||
} from "../config/config.js";
|
|
||||||
import { resolveGatewayService } from "../daemon/service.js";
|
import { resolveGatewayService } from "../daemon/service.js";
|
||||||
import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js";
|
import { stylePromptHint, stylePromptMessage, stylePromptTitle } from "../terminal/prompt-style.js";
|
||||||
import { resolveHomeDir } from "../utils.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";
|
type UninstallScope = "service" | "state" | "workspace" | "app";
|
||||||
|
|
||||||
@@ -157,16 +152,8 @@ export async function uninstallCommand(runtime: RuntimeEnv, opts: UninstallOptio
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dryRun = Boolean(opts.dryRun);
|
const dryRun = Boolean(opts.dryRun);
|
||||||
const cfg = loadConfig();
|
const { stateDir, configPath, oauthDir, configInsideState, oauthInsideState, workspaceDirs } =
|
||||||
const stateDir = resolveStateDir();
|
resolveCleanupPlanFromDisk();
|
||||||
const configPath = resolveConfigPath();
|
|
||||||
const oauthDir = resolveOAuthDir();
|
|
||||||
const { configInsideState, oauthInsideState, workspaceDirs } = buildCleanupPlan({
|
|
||||||
cfg,
|
|
||||||
stateDir,
|
|
||||||
configPath,
|
|
||||||
oauthDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (scopes.has("service")) {
|
if (scopes.has("service")) {
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
|
|||||||
Reference in New Issue
Block a user