Class: EasyAI::Command::Claude
Constant Summary
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
#args_help_flag
Class Method Summary
collapse
Instance Method Summary
collapse
run
Constructor Details
#initialize(argv) ⇒ Claude
Returns a new instance of Claude.
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/easyai/command/claude.rb', line 38
def initialize(argv)
@no_keychain = argv.flag?('no-keychain')
@verbose_mode = argv.flag?('verbose')
super
remaining_args = @argv.remainder!
if remaining_args.first && File.exist?(remaining_args.first) && remaining_args.first.end_with?('.json')
@config_file = remaining_args.shift
end
@claude_args = remaining_args
end
|
Class Method Details
.options ⇒ Object
31
32
33
34
35
36
|
# File 'lib/easyai/command/claude.rb', line 31
def self.options
[
['--no-keychain', '禁用自动密码存储'],
['--verbose', '显示详细信息(包括完整的代理和令牌)']
].concat(super)
end
|
Instance Method Details
#run ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/easyai/command/claude.rb', line 61
def run
begin
remote_config = nil
if @config_file
print_status("📁 使用本地配置", File.basename(@config_file))
remote_config = load_local_config(@config_file)
print_success("配置加载成功") if remote_config
else
print_status("🔄 获取远程配置", "默认用户")
options = { no_keychain: @no_keychain }
remote_config = ConfigManager.download_user_config(nil, options)
print_success("配置加载成功") if remote_config
end
if remote_config.nil?
print_warning("使用本地配置")
remote_config = load_local_yaml_config
if remote_config.empty?
print_error("未找到有效配置")
puts " 请先运行: #{'easyai --setup'.yellow}"
exit 1
end
end
print_status("🔐 配置认证", "Claude OAuth")
unless Auth::AuthClaude.configure(remote_config, nil)
print_error("配置认证失败")
exit 1
end
print_success("认证配置完成")
env = build_environment(remote_config)
export_environment_variables(env)
puts "─" * 60
puts "🚀 #{'Claude CLI 已启动'.green}"
puts "─" * 60
puts
exec(env, 'claude', *@claude_args)
rescue => e
print_error("Claude 命令执行失败: #{e.message}")
puts " 请检查配置文件和网络连接"
puts " 错误详情: #{e.class.name}" if @verbose_mode
exit 1
end
end
|
#validate! ⇒ Object
56
57
58
59
|
# File 'lib/easyai/command/claude.rb', line 56
def validate!
super
help! '未找到 Claude CLI。请安装:npm install -g @anthropic-ai/claude-code' unless claude_available?
end
|