1// `nzip where <target>` — print the local directory this machine pushed a site2// from. Purely local: reads the breadcrumb registry, never touches the server,3// so it stays fast enough for `cd "$(nzip where personal:plan)"`.45import { resolveCliTarget } from "../lib/api.ts";6import type { Config } from "../lib/config.ts";7import { lookup } from "../lib/paths.ts";8import { amber, dim, emit, fail } from "../lib/fmt.ts";910export async function cmdWhere(config: Config, raw: string | undefined): Promise<void> {11 if (!raw) fail("usage: nzip where <target>");1213 const q = /^[0-9a-f]{4}$/.test(raw) ? { address: raw } : (() => {14 let resolved: string;15 try {16 resolved = resolveCliTarget(raw, config);17 } catch (e) {18 return fail((e as Error).message);19 }20 const [vault, alias] = resolved.split(":");21 return { vault, alias };22 })();2324 const entry = await lookup(q);25 if (!entry) {26 fail(27 `no local path tracked for "${raw}" on this machine`,28 "it was pushed elsewhere (or before tracking existed) — push it again from its directory to record the path",29 );30 }3132 let exists = false;33 try {34 await Deno.stat(entry.path); // dir, or a file for single-file pushes35 exists = true;36 } catch {37 exists = false;38 }3940 emit(41 () => {42 console.log(entry.path); // bare path on stdout for `cd "$(nzip where …)"`43 if (!exists) {44 console.error(dim(` ${amber("↳")} directory no longer exists (moved or deleted)`));45 }46 },47 {48 ok: true,49 target: raw,50 address: entry.address,51 vault: entry.vault ?? null,52 alias: entry.alias ?? null,53 path: entry.path,54 exists,55 url: entry.url,56 expiresAt: entry.expiresAt,57 pushedAt: entry.pushedAt,58 },59 );60}