GitNexus/gitnexus/src/cli/command-banner.ts
Gergő Magyar c0c3fa18a9
chore: release v1.6.11 (#3177)
* chore: release v1.6.11

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(test): read /api/info version from package.json

server-info unit tests hardcoded 1.6.10 while buildServerInfo reads
package.json, so the 1.6.11 bump failed ubuntu coverage 3/3.

Co-authored-by: Cursor <cursoragent@cursor.com>

* refactor: read the published version from one helper

Release bumps kept breaking tests that each re-required package.json.
packageVersion() is now the single read for CLI, MCP, serve, and those tests.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 20:02:37 +01:00

68 lines
1.7 KiB
TypeScript

/**
* One-line identity printed before every CLI action:
* `GitNexus Analyzer (1.6.10)`. Goes to stderr so stdout stays
* pipe/JSON-safe (`gitnexus query … | jq`, `status --json`).
*/
import type { Command } from 'commander';
import { packageVersion } from '../core/package-version.js';
const SKIP_COMMAND_BANNER = new Set(['__update-check', 'help']);
const SPECIAL_TITLES: Record<string, string> = {
analyze: 'Analyzer',
mcp: 'MCP',
};
export function installedCliVersion(): string {
return packageVersion();
}
export function commandDisplayName(name: string): string {
return (
SPECIAL_TITLES[name] ??
name
.split('-')
.filter(Boolean)
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join(' ')
);
}
export function commandBannerTitle(command: Command): string {
const names: string[] = [];
for (
let current: Command | null | undefined = command;
current?.parent;
current = current.parent
) {
names.unshift(current.name());
}
return names.map(commandDisplayName).join(' ');
}
export function formatCommandBanner(
title: string,
version: string = installedCliVersion(),
): string {
if (!title) return '';
return version ? `\n GitNexus ${title} (${version})\n` : `\n GitNexus ${title}\n`;
}
export interface WriteCommandBannerDependencies {
write?: (text: string) => void;
version?: string;
}
export function writeCommandBanner(
command: Command,
deps: WriteCommandBannerDependencies = {},
): void {
if (SKIP_COMMAND_BANNER.has(command.name())) return;
const text = formatCommandBanner(
commandBannerTitle(command),
deps.version ?? installedCliVersion(),
);
if (!text) return;
(deps.write ?? ((line) => process.stderr.write(line)))(text);
}