feat(cli): add --data-dir flag to isolate local state

Add --data-dir option to all CLI commands, allowing users to override
the default ~/.paperclip root for config, context, database, logs, and
storage. Includes preAction hook to auto-derive --config and --context
paths when --data-dir is set. Add unit tests and doc updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dotta
2026-03-02 14:20:37 -06:00
parent ba388dc382
commit cabf09e7b1
8 changed files with 176 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import { ApiRequestError, PaperclipApiClient } from "../../client/http.js";
export interface BaseClientOptions {
config?: string;
dataDir?: string;
context?: string;
profile?: string;
apiBase?: string;
@@ -25,6 +26,7 @@ export interface ResolvedClientContext {
export function addCommonClientOptions(command: Command, opts?: { includeCompany?: boolean }): Command {
command
.option("-c, --config <path>", "Path to Paperclip config file")
.option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")
.option("--context <path>", "Path to CLI context file")
.option("--profile <name>", "CLI context profile name")
.option("--api-base <url>", "Base URL for the Paperclip API")

View File

@@ -10,6 +10,7 @@ import {
import { printOutput } from "./common.js";
interface ContextOptions {
dataDir?: string;
context?: string;
profile?: string;
json?: boolean;
@@ -28,6 +29,7 @@ export function registerContextCommands(program: Command): void {
context
.command("show")
.description("Show current context and active profile")
.option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")
.option("--context <path>", "Path to CLI context file")
.option("--profile <name>", "Profile to inspect")
.option("--json", "Output raw JSON")
@@ -48,6 +50,7 @@ export function registerContextCommands(program: Command): void {
context
.command("list")
.description("List available context profiles")
.option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")
.option("--context <path>", "Path to CLI context file")
.option("--json", "Output raw JSON")
.action((opts: ContextOptions) => {
@@ -66,6 +69,7 @@ export function registerContextCommands(program: Command): void {
.command("use")
.description("Set active context profile")
.argument("<profile>", "Profile name")
.option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")
.option("--context <path>", "Path to CLI context file")
.action((profile: string, opts: ContextOptions) => {
setCurrentProfile(profile, opts.context);
@@ -75,6 +79,7 @@ export function registerContextCommands(program: Command): void {
context
.command("set")
.description("Set values on a profile")
.option("-d, --data-dir <path>", "Paperclip data directory root (isolates state from ~/.paperclip)")
.option("--context <path>", "Path to CLI context file")
.option("--profile <name>", "Profile name (default: current profile)")
.option("--api-base <url>", "Default API base URL")