import { VERSION } from "../version"; import type { CliCommandContext, CliCommandDef, CliDispatchResult, CliLaunchRequest } from "../types/plugin"; import type { LoadedExternalPlugin } from "../plugins/loader"; import { loadCliConfigIfAvailable } from "./context"; import { parseCliGlobalArgs } from "./options"; import { buildCliCommandRegistry, createCliCommandContext, normalizeCliCommandToken, normalizeCliDispatchResult, type CliCommandRegistry, } from "./registry"; import { CLI_COMMAND_GROUPS, describeCliCommand, renderCliHelp, renderCommandHelp, suggestCliCommand, type CliHelpEntry, } from "./help"; import { parsePaneFunctionArgs } from "./pane-functions/options"; import { fail, inferCliErrorOptions, printCliError } from "./errors"; import { setCliColorEnabledOverride } from "../utils/cli-output"; import { search, searchCandidatesForCli, buildSearchReport } from "./commands/search"; import { ticker } from "./commands/ticker"; import { apiCliCommand } from "./commands/api"; import { marketDataCliCommands } from "./commands/market"; import { overviewCliCommands } from "./commands/overview"; import { remoteCliCommand } from "./commands/remote"; import { createSystemCliCommands } from "./commands/system"; import { brokerCliCommand, ibkrCliCommand, rssCliCommand, } from "./commands/automation"; import { installPlugin, listPlugins, parseGitHubRef, removePlugin, resolveRegistryPin, updatePlugins, } from "./commands/plugins"; import { runPaneCatalog, runPaneFunction, runPaneScreenshot } from "./pane-functions"; function createCoreCliCommands( helpEntries: () => CliHelpEntry[], lookupCommand: (token: string) => CliCommandDef | null, allCommands: () => CliCommandDef[], ): CliCommandDef[] { const launchUiRequest: CliLaunchRequest = { applyConfig: (config) => ({ config }), }; return [ { name: "help", description: "Show every command, or the usage, options, and examples for one", help: { group: CLI_COMMAND_GROUPS.app, usage: ["help [command]", " --help"], examples: ["help", "help quote", "quote --help"], }, execute: (args, ctx) => { const topic = args[0]; if (topic) { const command = lookupCommand(topic); if (!command) failUnknownCommand(topic, allCommands()); printCommandHelp(command, ctx); return; } if (ctx.cliOptions.format === "text") { printHelpText(renderCliHelp(helpEntries(), VERSION, CLI_DESCRIPTION), ctx); return; } ctx.printResult({ data: allCommands().map(describeCliCommand) }); }, }, { name: "launch-ui", aliases: ["ui"], description: "Open the terminal UI, like plain gloomberb", help: { group: CLI_COMMAND_GROUPS.app, usage: ["launch-ui"], }, execute: () => ({ kind: "launch-ui", request: launchUiRequest }), }, { name: "search", description: "Search tickers and company names", help: { group: CLI_COMMAND_GROUPS.research, usage: ["search "], examples: ["search nvidia", "search \"berkshire hathaway\""], }, execute: async (args, ctx) => { const query = args.join(" "); await search(query, { initMarketData: ctx.initMarketData, fail: ctx.fail, ...(ctx.cliOptions.format === "text" ? {} : { printResult: ctx.printResult }), }); }, }, { name: "ticker", description: "Show the full research report for one symbol", help: { group: CLI_COMMAND_GROUPS.research, usage: ["ticker "], examples: ["ticker AAPL", "ticker 7203.T", "ticker AAPL --json"], }, execute: async (args, ctx) => { const symbol = args[0]; if (!symbol) { ctx.fail("Usage: gloomberb ticker "); } await ticker(symbol!, { initMarketData: ctx.initMarketData, fail: ctx.fail, ...(ctx.cliOptions.format === "text" ? {} : { printResult: ctx.printResult }), }); }, }, { name: "catalog", aliases: ["functions", "capabilities"], description: "Find market functions to run with fn or capture with shot", help: { group: CLI_COMMAND_GROUPS.functions, usage: ["catalog [query] [--all] [--bot-safe]"], options: [ { flags: "--all", description: "List every match instead of the first 25" }, { flags: "--bot-safe", description: "Only functions with a verified unattended report" }, ], examples: ["catalog", "catalog options", "catalog HP"], }, execute: async (args, ctx) => { await runPaneCatalog(args, ctx); }, }, { name: "fn", aliases: ["function"], description: "Run a market function and print its report", help: { group: CLI_COMMAND_GROUPS.functions, usage: ["fn [argument] [options]"], options: [ { flags: "--