From bd1b7d6f8cf2bd802da225ead8e254814bacb8cc Mon Sep 17 00:00:00 2001 From: Pavel Jbanov Date: Tue, 12 Nov 2024 11:24:32 -0500 Subject: [PATCH] feat: added -o/--open option to `genkit start` to pop up a browser (#1247) --- genkit-tools/cli/src/commands/start.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/genkit-tools/cli/src/commands/start.ts b/genkit-tools/cli/src/commands/start.ts index c6a3c7490..135893398 100644 --- a/genkit-tools/cli/src/commands/start.ts +++ b/genkit-tools/cli/src/commands/start.ts @@ -19,11 +19,13 @@ import { logger } from '@genkit-ai/tools-common/utils'; import { spawn } from 'child_process'; import { Command } from 'commander'; import getPort, { makeRange } from 'get-port'; +import open from 'open'; import { startManager } from '../utils/manager-utils'; interface RunOptions { noui?: boolean; port?: string; + open?: boolean; } /** Command to run code in dev mode and/or the Dev UI. */ @@ -31,6 +33,7 @@ export const start = new Command('start') .description('runs a command in Genkit dev mode') .option('-n, --noui', 'do not start the Dev UI', false) .option('-p, --port', 'port for the Dev UI') + .option('-o, --open', 'Open the browser on UI start up') .action(async (options: RunOptions) => { let runtimePromise = Promise.resolve(); if (start.args.length > 0) { @@ -69,7 +72,9 @@ export const start = new Command('start') uiPromise = startManager(true).then((manager) => startServer(manager, port) ); + if (options.open) { + open(`http://localhost:${port}`); + } } - await Promise.all([runtimePromise, uiPromise]); });