Private
Public Access
1
0

feat: 增强三个 CLI 工具配置脚本

- Gemini CLI: 添加 GEMINI_MODEL 环境变量、settings.json 输出及备份逻辑
- Codex: 修复模型名称一致性 (gpt-5-codex)、添加 auth.json 备份逻辑
- Claude Code: 添加 VSCode 插件 config.json 配置支持
- CLAUDE.md: 重构文档,添加三个工具配置差异表

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-11 18:15:54 +08:00
parent badf8e6bb6
commit 2314140bce
9 changed files with 292 additions and 497 deletions

View File

@@ -37,7 +37,7 @@ print_error() {
# Function to check if jq is installed
check_jq() {
if ! command -v jq &> /dev/null; then
if ! command -v jq &>/dev/null; then
print_error "jq is required but not installed."
print_info "Please install jq:"
print_info " macOS: brew install jq"
@@ -54,6 +54,12 @@ backup_settings() {
cp "$CLAUDE_SETTINGS_FILE" "$backup_file"
print_info "Backed up existing settings to: $backup_file"
fi
local config_json_path="$CLAUDE_CONFIG_DIR/config.json"
if [ -f "$config_json_path" ]; then
local backup_file="${config_json_path}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$config_json_path" "$backup_file"
print_info "Backed up existing config to: $backup_file"
fi
}
# Function to create settings directory
@@ -128,7 +134,7 @@ test_api_connection() {
create_settings() {
local base_url="$1"
local api_key="$2"
# Create JSON using jq to ensure proper escaping
local settings_json
settings_json=$(jq -n \
@@ -140,19 +146,29 @@ create_settings() {
"ANTHROPIC_AUTH_TOKEN": $api_key,
"DISABLE_TELEMETRY": 1,
"DISABLE_ERROR_REPORTING": 1,
"API_TIMEOUT_MS": 600000,
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1
}
}')
# Validate JSON
if ! echo "$settings_json" | jq . > /dev/null 2>&1; then
if ! echo "$settings_json" | jq . >/dev/null 2>&1; then
print_error "Generated settings JSON is invalid"
return 1
fi
# Write settings file
echo "$settings_json" > "$CLAUDE_SETTINGS_FILE"
echo "$settings_json" >"$CLAUDE_SETTINGS_FILE"
print_success "Claude Code settings written to: $CLAUDE_SETTINGS_FILE"
# Write config.json for VSCode Claude extension
local config_json_path="$CLAUDE_CONFIG_DIR/config.json"
cat <<EOF > "$config_json_path"
{
"primaryApiKey": "xcodecli"
}
EOF
print_success "VSCode Claude config written to: $config_json_path"
}
# Function to display current settings
@@ -172,10 +188,10 @@ main() {
print_info "Claude Code Configuration Script for XCodeCLI"
echo "======================================================="
echo
# Check dependencies
check_jq
# Parse command line arguments
local api_key=""
local test_only=false
@@ -188,20 +204,20 @@ main() {
while [[ $# -gt 0 ]]; do
case $1 in
-k|--key)
api_key="$2"
shift 2
;;
-t|--test)
test_only=true
shift
;;
-s|--show)
show_settings=true
shift
;;
-h|--help)
cat <<EOF
-k | --key)
api_key="$2"
shift 2
;;
-t | --test)
test_only=true
shift
;;
-s | --show)
show_settings=true
shift
;;
-h | --help)
cat <<EOF
Usage: $0 [OPTIONS]
This script automatically tests multiple API endpoints and selects the working one:
@@ -225,22 +241,22 @@ Interactive mode (no arguments):
Environment Variables:
API_KEY API key for authentication
EOF
exit 0
;;
*)
print_error "Unknown option: $1"
print_info "Use --help for usage information"
exit 1
;;
exit 0
;;
*)
print_error "Unknown option: $1"
print_info "Use --help for usage information"
exit 1
;;
esac
done
# Show settings and exit if requested
if [ "$show_settings" = true ]; then
display_settings
exit 0
fi
# Interactive mode if no API key provided
if [ -z "$api_key" ]; then
print_info "Interactive setup mode"
@@ -256,19 +272,19 @@ EOF
fi
done
fi
# Validate inputs
if [ -z "$api_key" ]; then
print_error "API key is required"
print_info "Use --help for usage information"
exit 1
fi
# Validate API key
if ! validate_api_key "$api_key"; then
exit 1
fi
print_info "API Key: ${api_key:0:8}...${api_key: -4}"
echo
@@ -294,19 +310,19 @@ EOF
else
print_info "Selected working base URL: $base_url"
fi
# Exit if test only
if [ "$test_only" = true ]; then
print_success "API test completed successfully"
exit 0
fi
# Create settings directory
create_settings_dir
# Backup existing settings
backup_settings
# Create new settings
if create_settings "$base_url" "$api_key"; then
echo
@@ -317,7 +333,7 @@ EOF
print_info " claude --version"
print_info ""
print_info "Configuration file location: $CLAUDE_SETTINGS_FILE"
if [ -f "$CLAUDE_SETTINGS_FILE" ]; then
echo
print_info "Current settings:"