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.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/easyai/command/claude.rb', line 48
def initialize(argv)
@platform_flag = argv.flag?('platform')
@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
40
41
42
43
44
45
46
|
# File 'lib/easyai/command/claude.rb', line 40
def self.options
[
['--platform', '选择认证平台(交互式选择)'],
['--no-keychain', '禁用自动密码存储'],
['--verbose', '显示详细信息']
].concat(super)
end
|
Instance Method Details
#run ⇒ Object
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/easyai/command/claude.rb', line 72
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,
verbose: @verbose_mode,
tool_type: "claude", platform_flag: @platform_flag }
remote_config = ConfigManager.download_user_config(nil, options)
if remote_config == :user_cancelled
print_error("用户取消了授权登录")
exit 0
end
print_success("配置加载成功") if remote_config
end
if remote_config && remote_config['_config_path']&.include?('claude_auth')
unless check_claude_auth_environment
exit 1
end
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
67
68
69
70
|
# File 'lib/easyai/command/claude.rb', line 67
def validate!
super
help! '未找到 Claude CLI。请安装:npm install -g @anthropic-ai/claude-code' unless claude_available?
end
|