update cli description for run

This commit is contained in:
dswbx
2025-03-14 15:37:51 +01:00
parent 6a6a7a9f26
commit 5697b7891a
2 changed files with 18 additions and 13 deletions

View File

@@ -22,6 +22,7 @@ const isBun = typeof Bun !== "undefined";
export const run: CliCommand = (program) => { export const run: CliCommand = (program) => {
program program
.command("run") .command("run")
.description("run an instance")
.addOption( .addOption(
new Option("-p, --port <port>", "port to run on") new Option("-p, --port <port>", "port to run on")
.env("PORT") .env("PORT")

View File

@@ -1,32 +1,36 @@
import { PostHog } from "posthog-js-lite"; import { PostHog } from "posthog-js-lite";
import { getVersion } from "cli/utils/sys"; import { getVersion } from "cli/utils/sys";
import { $console, env } from "core"; import { $console, env, isDebug } from "core";
type Properties = { [p: string]: any }; type Properties = { [p: string]: any };
let posthog: PostHog | null = null; let posthog: PostHog | null = null;
let version: string | null = null; let version: string | null = null;
const enabled = env("cli_telemetry"); const is_debug = isDebug() || !!process.env.LOCAL;
const enabled = env("cli_telemetry", !is_debug);
export async function init() { export async function init(): Promise<boolean> {
try { try {
if (!enabled) { if (!enabled) {
$console.debug("Telemetry disabled"); $console.debug("telemetry disabled");
return; return false;
} }
$console.debug("Init telemetry"); $console.debug("init telemetry");
if (!posthog) { if (!posthog) {
posthog = new PostHog(process.env.POSTHOG_KEY!, { posthog = new PostHog(process.env.PUBLIC_POSTHOG_KEY!, {
host: process.env.POSTHOG_HOST!, host: process.env.PUBLIC_POSTHOG_HOST!,
disabled: !enabled, disabled: !enabled,
}); });
} }
version = await getVersion(); version = await getVersion();
return true;
} catch (e) { } catch (e) {
$console.debug("Failed to initialize telemetry", e); $console.debug("failed to initialize telemetry", e);
} }
return false;
} }
export function client(): PostHog { export function client(): PostHog {
@@ -46,10 +50,10 @@ export function capture(event: string, properties: Properties = {}): void {
...properties, ...properties,
version: version!, version: version!,
}; };
$console.debug("Capture", name, props); $console.debug(`capture "${name}"`, props);
client().capture(name, props); client().capture(name, props);
} catch (e) { } catch (e) {
$console.debug("Failed to capture telemetry", e); $console.debug("failed to capture telemetry", e);
} }
} }
@@ -65,11 +69,11 @@ export async function flush() {
try { try {
if (!enabled) return; if (!enabled) return;
$console.debug("Flush telemetry"); $console.debug("flush telemetry");
if (posthog) { if (posthog) {
await posthog.flush(); await posthog.flush();
} }
} catch (e) { } catch (e) {
$console.debug("Failed to flush telemetry", e); $console.debug("failed to flush telemetry", e);
} }
} }