cli/src/commands/status.tsblame
View source
0d9d7231import { log } from "@clack/prompts";
0d9d7232import { existsSync, readFileSync } from "node:fs";
0d9d7233import { join, dirname } from "node:path";
0d9d7234import { execSync } from "node:child_process";
0d9d7235
0d9d7236export async function status() {
0d9d7237 let dir = process.cwd();
0d9d7238 let slDir: string | null = null;
0d9d7239 while (dir !== dirname(dir)) {
0d9d72310 if (existsSync(join(dir, ".sl", "config"))) {
0d9d72311 slDir = join(dir, ".sl");
0d9d72312 break;
0d9d72313 }
0d9d72314 dir = dirname(dir);
0d9d72315 }
0d9d72316
0d9d72317 if (!slDir) {
0d9d72318 log.error("Not in a Grove repository.");
0d9d72319 process.exit(1);
0d9d72320 }
0d9d72321
0d9d72322 const config = readFileSync(join(slDir, "config"), "utf-8");
0d9d72323 const repoMatch = config.match(/reponame\s*=\s*(.+)/);
0d9d72324 const ownerMatch = config.match(/owner\s*=\s*(.+)/);
0d9d72325 const branchMatch = config.match(/selectivepulldefault\s*=\s*(.+)/);
0d9d72326
0d9d72327 const repo = repoMatch?.[1]?.trim() ?? "unknown";
0d9d72328 const owner = ownerMatch?.[1]?.trim() ?? "unknown";
0d9d72329 const branch = branchMatch?.[1]?.trim() ?? "main";
0d9d72330
0d9d72331 let current = "";
0d9d72332 try {
0d9d72333 current = execSync("sl log -r . --template {bookmarks}", { cwd: dir, stdio: "pipe" }).toString().trim();
0d9d72334 } catch {}
0d9d72335
0d9d72336 const lines = [
0d9d72337 `Repo: ${owner}/${repo}`,
0d9d72338 `Branch: ${branch}`,
0d9d72339 ];
0d9d72340 if (current) lines.push(`At: ${current}`);
0d9d72341 lines.push(`URL: https://grove.host/${owner}/${repo}`);
0d9d72342
0d9d72343 log.info(lines.join("\n"));
0d9d72344}