From 5697b7891a24d9bc41ce16a5d950a6e928964213 Mon Sep 17 00:00:00 2001 From: dswbx Date: Fri, 14 Mar 2025 15:37:51 +0100 Subject: [PATCH] update cli description for `run` --- app/src/cli/commands/run/run.ts | 1 + app/src/cli/utils/telemetry.ts | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/cli/commands/run/run.ts b/app/src/cli/commands/run/run.ts index ddfeb1a..ff15f10 100644 --- a/app/src/cli/commands/run/run.ts +++ b/app/src/cli/commands/run/run.ts @@ -22,6 +22,7 @@ const isBun = typeof Bun !== "undefined"; export const run: CliCommand = (program) => { program .command("run") + .description("run an instance") .addOption( new Option("-p, --port ", "port to run on") .env("PORT") diff --git a/app/src/cli/utils/telemetry.ts b/app/src/cli/utils/telemetry.ts index ce819b3..9fddb42 100644 --- a/app/src/cli/utils/telemetry.ts +++ b/app/src/cli/utils/telemetry.ts @@ -1,32 +1,36 @@ import { PostHog } from "posthog-js-lite"; import { getVersion } from "cli/utils/sys"; -import { $console, env } from "core"; +import { $console, env, isDebug } from "core"; type Properties = { [p: string]: any }; let posthog: PostHog | 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 { try { if (!enabled) { - $console.debug("Telemetry disabled"); - return; + $console.debug("telemetry disabled"); + return false; } - $console.debug("Init telemetry"); + $console.debug("init telemetry"); if (!posthog) { - posthog = new PostHog(process.env.POSTHOG_KEY!, { - host: process.env.POSTHOG_HOST!, + posthog = new PostHog(process.env.PUBLIC_POSTHOG_KEY!, { + host: process.env.PUBLIC_POSTHOG_HOST!, disabled: !enabled, }); } version = await getVersion(); + return true; } catch (e) { - $console.debug("Failed to initialize telemetry", e); + $console.debug("failed to initialize telemetry", e); } + + return false; } export function client(): PostHog { @@ -46,10 +50,10 @@ export function capture(event: string, properties: Properties = {}): void { ...properties, version: version!, }; - $console.debug("Capture", name, props); + $console.debug(`capture "${name}"`, props); client().capture(name, props); } 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 { if (!enabled) return; - $console.debug("Flush telemetry"); + $console.debug("flush telemetry"); if (posthog) { await posthog.flush(); } } catch (e) { - $console.debug("Failed to flush telemetry", e); + $console.debug("failed to flush telemetry", e); } }