-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbrowse.ts
More file actions
29 lines (26 loc) · 1.01 KB
/
browse.ts
File metadata and controls
29 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Command } from "@cliffy/command";
import open from "open";
import { doWithSpinner } from "~/cmd/utils.ts";
import VTClient from "~/vt/vt/VTClient.ts";
import { findVtRoot } from "~/vt/vt/utils.ts";
import { delay } from "@std/async";
import { getBranch } from "~/sdk.ts";
export const browseCmd = new Command()
.name("browse")
.description("Open a Val's main page in a web browser")
.option("--no-browser", "Print destination url instead of opening browser")
.action(async ({ browser }: { browser?: boolean }) => {
const vt = VTClient.from(await findVtRoot(Deno.cwd()));
const vtState = await vt.getMeta().loadVtState();
const branch = await getBranch(
vtState.val.id,
vtState.branch.id,
);
if (browser) {
await doWithSpinner("Opening Val url...", async (spinner) => {
await open(branch.links.html);
await delay(150);
spinner.succeed(`Val url opened in browser:\n${branch.links.html}`);
});
} else console.log(`${branch.links.html}`);
});