@civic/hub-bridge
Version:
Stdio <-> HTTP/SSE MCP bridge with Civic auth handling
110 lines • 3.66 kB
JavaScript
/**
* cli/index.ts
*
* Command-line interface utilities for the Hub Bridge.
* Handles argument parsing, version display, help text, and installation commands.
*/
import { runInstaller, AVAILABLE_TARGETS } from '../installer/index.js';
import { readFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
/**
* Get version information - try version.ts first (for compiled builds), then package.json
*/
async function loadVersion() {
// First try to import from version.ts (available after prebuild)
try {
const versionModule = await import('../version.js');
return versionModule.version;
}
catch {
// Fallback to reading package.json (for development)
try {
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageJson = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf8'));
return packageJson.version;
}
catch {
// Ultimate fallback version if nothing works
return '0.1.0';
}
}
}
/**
* Display version information
*/
export async function showVersion() {
const version = await loadVersion();
console.log(`Civic Hub Bridge v${version}`);
}
/**
* Display help information
*/
export async function showHelp() {
const version = await loadVersion();
console.log(`Civic Hub Bridge v${version}`);
console.log('Usage: hub-bridge [command] [options]');
console.log('');
console.log('Commands:');
console.log(` install <target> Install bridge for target (${AVAILABLE_TARGETS.join(', ')})`);
console.log('');
console.log('Options:');
console.log(' --version, -v Show version information');
console.log(' --help, -h Show this help message');
console.log('');
console.log('Environment Variables:');
console.log(' MCP_REMOTE_URL Remote MCP server URL');
console.log(' CLIENT_ID OAuth client ID');
console.log(' NO_LOGIN Skip authentication (use CLIENT_ID as token)');
console.log(' NO_AUTH_CAPTURE Skip third-party service authorization');
}
/**
* Handle installer command
*/
async function handleInstaller(args) {
if (args.length > 0 && args[0] === 'install') {
if (args.length < 2) {
console.error('Error: Missing installation target. Use: hub-bridge install <target>');
console.error(`Available targets: ${AVAILABLE_TARGETS.join(', ')}`);
throw new Error('Missing installation target');
}
const target = args[1];
try {
await runInstaller(target);
// Successfully completed installation
return true;
}
catch (error) {
console.error(`Error during installation: ${error}`);
throw error;
}
}
return false;
}
/**
* Handle CLI arguments (version, help, install)
* Returns true if the application should exit (command was handled)
*/
export async function handleCliArguments() {
const args = process.argv.slice(2);
// Handle --version flag
if (args.includes('--version') || args.includes('-v')) {
await showVersion();
return true;
}
// Handle --help flag
if (args.includes('--help') || args.includes('-h')) {
await showHelp();
return true;
}
// Handle install command
return await handleInstaller(args);
}
/**
* Get version string for logging
*/
export async function getVersion() {
return await loadVersion();
}
//# sourceMappingURL=index.js.map