aico-claude-code
Version:
Claude Code CLI 的网页用户界面
93 lines (85 loc) • 2.77 kB
JavaScript
/**
* CLI argument parser for Claude Code UI
*
* Provides command-line interface for running the Claude Code UI server
*/
import { Command } from 'commander';
const program = new Command();
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Read version from package.json
let version;
try {
const packageJson = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
version = packageJson.version;
} catch (error) {
version = '1.0.0';
}
export function parseCliArgs() {
// Get default port from environment
const defaultPort = parseInt(process.env.PORT || '3000', 10);
const defaultVitePort = parseInt(process.env.VITE_PORT || '3001', 10);
program
.name('claude-ui')
.version(version)
.description('Claude Code UI - Web-based interface for Claude Code CLI')
.option(
'-p, --port <port>',
'Backend server port',
(value) => {
const parsed = parseInt(value, 10);
if (isNaN(parsed)) {
throw new Error(`Invalid port number: ${value}`);
}
return parsed;
},
defaultPort
)
.option(
'--vite-port <port>',
'Frontend development server port',
(value) => {
const parsed = parseInt(value, 10);
if (isNaN(parsed)) {
throw new Error(`Invalid Vite port number: ${value}`);
}
return parsed;
},
defaultVitePort
)
.option(
'--host <host>',
'Host address to bind to (use 0.0.0.0 for all interfaces)',
'127.0.0.1'
)
.option(
'--claude-path <path>',
'Path to claude executable (overrides automatic detection)'
)
.option('-d, --debug', 'Enable debug mode', false)
.option('--no-browser', 'Do not open browser automatically', false)
.option('--dev', 'Run in development mode (with hot reload)', false)
.option('--prod', 'Run in production mode (built version)', false)
.option('--config <path>', 'Path to configuration file')
.option('--log-level <level>', 'Set log level (error, warn, info, debug)', 'info');
program.parse(process.argv);
const options = program.opts();
// Handle DEBUG environment variable
const debugEnv = process.env.DEBUG;
const debugFromEnv = debugEnv?.toLowerCase() === 'true' || debugEnv === '1';
return {
port: options.port,
vitePort: options.vitePort,
host: options.host,
claudePath: options.claudePath,
debug: options.debug || debugFromEnv,
openBrowser: !options.noBrowser,
devMode: options.dev,
prodMode: options.prod,
configPath: options.config,
logLevel: options.logLevel
};
}