From 0f6859678cca14b42c01642f0cf0e33016855500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Mon, 18 May 2026 14:03:10 +0000 Subject: [PATCH] refactor: merge cas get/cat into get, default hides timestamp - Remove `cas cat` command - `cas get` now returns {type, payload} by default - Add `--timestamp` flag to include timestamp Refs #328 --- packages/cli-uwf/src/cli.ts | 20 ++++---------------- packages/cli-uwf/src/commands/cas.ts | 18 +++++------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/packages/cli-uwf/src/cli.ts b/packages/cli-uwf/src/cli.ts index 9002cc1..1f128ef 100755 --- a/packages/cli-uwf/src/cli.ts +++ b/packages/cli-uwf/src/cli.ts @@ -12,7 +12,6 @@ import { import { cmdWorkflowList, cmdWorkflowPut, cmdWorkflowShow } from "./commands/workflow.js"; import { cmdSetup, cmdSetupInteractive } from "./commands/setup.js"; import { - cmdCasCat, cmdCasGet, cmdCasHas, cmdCasPut, @@ -185,24 +184,13 @@ const cas = program.command("cas").description("Content-addressable storage oper cas .command("get") - .description("Read a CAS node as JSON") + .description("Read a CAS node (type + payload; use --timestamp to include timestamp)") .argument("", "CAS hash (13 char)") - .action((hash: string) => { + .option("--timestamp", "Include timestamp in output") + .action((hash: string, opts: { timestamp?: boolean }) => { const storageRoot = resolveStorageRoot(); runAction(async () => { - writeOutput(await cmdCasGet(storageRoot, hash)); - }); - }); - -cas - .command("cat") - .description("Output a CAS node (--payload for payload only)") - .argument("", "CAS hash (13 char)") - .option("--payload", "Output only the payload") - .action((hash: string, opts: { payload?: boolean }) => { - const storageRoot = resolveStorageRoot(); - runAction(async () => { - writeOutput(await cmdCasCat(storageRoot, hash, opts)); + writeOutput(await cmdCasGet(storageRoot, hash, opts)); }); }); diff --git a/packages/cli-uwf/src/commands/cas.ts b/packages/cli-uwf/src/commands/cas.ts index 934da7a..a580dc5 100644 --- a/packages/cli-uwf/src/commands/cas.ts +++ b/packages/cli-uwf/src/commands/cas.ts @@ -28,26 +28,18 @@ function readJsonArg(fileOrInline: string): unknown { export async function cmdCasGet( storageRoot: string, hash: string, + opts: { timestamp?: boolean }, ): Promise { const store = openStore(storageRoot); const node = store.get(hash); if (node === null) { throw new Error(`Node not found: ${hash}`); } - return node; -} - -export async function cmdCasCat( - storageRoot: string, - hash: string, - opts: { payload?: boolean }, -): Promise { - const store = openStore(storageRoot); - const node = store.get(hash); - if (node === null) { - throw new Error(`Node not found: ${hash}`); + if (opts.timestamp) { + return node; } - return opts.payload ? node.payload : node; + const { timestamp: _, ...rest } = node as Record; + return rest; } export async function cmdCasPut(