From 04efaa41f62a8fad3f62fbace881b90e8a002659 Mon Sep 17 00:00:00 2001 From: simosmik Date: Wed, 31 Dec 2025 07:42:01 +0000 Subject: [PATCH] feat: add custom port and database path options to CLI commands --- README.md | 42 ++++++++++++++----------------- server/cli.js | 68 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 5d51128..1b8cbac 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
Claude Code UI -

Claude Code UI

+

Cloud CLI (aka Claude Code UI)

@@ -88,32 +88,25 @@ claude-code-ui **To restart**: Stop with Ctrl+C and run `claude-code-ui` again. -### CLI Commands +### CLI Usage After global installation, you have access to both `claude-code-ui` and `cloudcli` commands: +| Command / Option | Short | Description | +|------------------|-------|-------------| +| `cloudcli` or `claude-code-ui` | | Start the server (default) | +| `cloudcli start` | | Start the server explicitly | +| `cloudcli status` | | Show configuration and data locations | +| `cloudcli help` | | Show help information | +| `cloudcli version` | | Show version information | +| `--port ` | `-p` | Set server port (default: 3001) | +| `--database-path ` | | Set custom database location | + +**Examples:** ```bash -# Start the server (default command) -claude-code-ui -cloudcli start - -# Show configuration and data locations -cloudcli status - -# Show help information -cloudcli help - -# Show version -cloudcli version -``` - -**The `cloudcli status` command shows you:** -- Installation directory location -- Database location (where credentials are stored) -- Current configuration (PORT, DATABASE_PATH, etc.) -- Claude projects folder location -- Configuration file location - +cloudcli # Start with defaults +cloudcli -p 8080 # Start on custom port +cloudcli status # Show current configuration ``` ### Run as Background Service (Recommended for Production) @@ -134,6 +127,9 @@ pm2 start claude-code-ui --name "claude-code-ui" # Or using the shorter alias pm2 start cloudcli --name "claude-code-ui" + +# Start on a custom port +pm2 start cloudcli --name "claude-code-ui" -- --port 8080 ``` diff --git a/server/cli.js b/server/cli.js index 818d91f..f817dd7 100755 --- a/server/cli.js +++ b/server/cli.js @@ -131,10 +131,10 @@ function showStatus() { console.log('\n' + c.dim('═'.repeat(60))); console.log(`\n${c.tip('[TIP]')} Hints:`); - console.log(` ${c.dim('>')} Set DATABASE_PATH env variable to use a custom database location`); - console.log(` ${c.dim('>')} Create .env file in installation directory for persistent config`); - console.log(` ${c.dim('>')} Run "claude-code-ui" or "cloudcli start" to start the server`); - console.log(` ${c.dim('>')} Access the UI at http://localhost:3001 (or custom PORT)\n`); + console.log(` ${c.dim('>')} Use ${c.bright('cloudcli --port 8080')} to run on a custom port`); + console.log(` ${c.dim('>')} Use ${c.bright('cloudcli --database-path /path/to/db')} for custom database`); + console.log(` ${c.dim('>')} Run ${c.bright('cloudcli help')} for all options`); + console.log(` ${c.dim('>')} Access the UI at http://localhost:${process.env.PORT || '3001'}\n`); } // Show help @@ -145,8 +145,8 @@ function showHelp() { ╚═══════════════════════════════════════════════════════════════╝ Usage: - claude-code-ui [command] - cloudcli [command] + claude-code-ui [command] [options] + cloudcli [command] [options] Commands: start Start the Claude Code UI server (default) @@ -154,10 +154,18 @@ Commands: help Show this help information version Show version information +Options: + -p, --port Set server port (default: 3001) + --database-path Set custom database location + -h, --help Show this help information + -v, --version Show version information + Examples: - $ claude-code-ui # Start the server - $ cloudcli status # Show configuration - $ cloudcli help # Show help + $ cloudcli # Start with defaults + $ cloudcli --port 8080 # Start on port 8080 + $ cloudcli -p 3000 # Short form for port + $ cloudcli start --port 4000 # Explicit start command + $ cloudcli status # Show configuration Environment Variables: PORT Set server port (default: 3001) @@ -165,11 +173,6 @@ Environment Variables: CLAUDE_CLI_PATH Set custom Claude CLI path CONTEXT_WINDOW Set context window size (default: 160000) -Configuration: - Create a .env file in the installation directory to set - persistent environment variables. Use 'cloudcli status' to - see the installation directory path. - Documentation: ${packageJson.homepage || 'https://github.com/siteboon/claudecodeui'} @@ -189,10 +192,45 @@ async function startServer() { await import('./index.js'); } +// Parse CLI arguments +function parseArgs(args) { + const parsed = { command: 'start', options: {} }; + + for (let i = 0; i < args.length; i++) { + const arg = args[i]; + + if (arg === '--port' || arg === '-p') { + parsed.options.port = args[++i]; + } else if (arg.startsWith('--port=')) { + parsed.options.port = arg.split('=')[1]; + } else if (arg === '--database-path') { + parsed.options.databasePath = args[++i]; + } else if (arg.startsWith('--database-path=')) { + parsed.options.databasePath = arg.split('=')[1]; + } else if (arg === '--help' || arg === '-h') { + parsed.command = 'help'; + } else if (arg === '--version' || arg === '-v') { + parsed.command = 'version'; + } else if (!arg.startsWith('-')) { + parsed.command = arg; + } + } + + return parsed; +} + // Main CLI handler async function main() { const args = process.argv.slice(2); - const command = args[0] || 'start'; + const { command, options } = parseArgs(args); + + // Apply CLI options to environment variables + if (options.port) { + process.env.PORT = options.port; + } + if (options.databasePath) { + process.env.DATABASE_PATH = options.databasePath; + } switch (command) { case 'start':