beniya 0.6.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/CHANGELOG_v0.7.0.md +280 -0
- data/CHANGELOG_v0.8.0.md +267 -0
- data/README.md +234 -0
- data/README_EN.md +162 -0
- data/bin/beniya +3 -0
- data/docs/PLUGIN_GUIDE.md +431 -0
- data/docs/plugin_example.rb +119 -0
- data/lib/beniya/command_mode.rb +72 -0
- data/lib/beniya/command_mode_ui.rb +122 -0
- data/lib/beniya/keybind_handler.rb +8 -0
- data/lib/beniya/plugin.rb +89 -0
- data/lib/beniya/plugin_config.rb +59 -0
- data/lib/beniya/plugin_manager.rb +84 -0
- data/lib/beniya/plugins/file_operations.rb +44 -0
- data/lib/beniya/terminal_ui.rb +105 -2
- data/lib/beniya/text_utils.rb +27 -11
- data/lib/beniya/version.rb +1 -1
- data/lib/beniya.rb +7 -0
- metadata +12 -2
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# Beniya プラグインガイド
|
|
2
|
+
|
|
3
|
+
Beniyaのプラグインシステムを使って、機能を拡張する方法を説明します。
|
|
4
|
+
|
|
5
|
+
## 目次
|
|
6
|
+
|
|
7
|
+
1. [プラグインの基本](#プラグインの基本)
|
|
8
|
+
2. [プラグインの作成](#プラグインの作成)
|
|
9
|
+
3. [プラグインの設定](#プラグインの設定)
|
|
10
|
+
4. [高度な機能](#高度な機能)
|
|
11
|
+
5. [トラブルシューティング](#トラブルシューティング)
|
|
12
|
+
|
|
13
|
+
## プラグインの基本
|
|
14
|
+
|
|
15
|
+
### プラグインとは?
|
|
16
|
+
|
|
17
|
+
プラグインは、Beniyaに新しい機能を追加するためのRubyモジュールです。
|
|
18
|
+
|
|
19
|
+
### プラグインの種類
|
|
20
|
+
|
|
21
|
+
1. **組み込みプラグイン**: Beniya本体に含まれる
|
|
22
|
+
- 場所: `lib/beniya/plugins/`
|
|
23
|
+
- 例: `FileOperations`
|
|
24
|
+
|
|
25
|
+
2. **ユーザープラグイン**: ユーザーが作成する
|
|
26
|
+
- 場所: `~/.beniya/plugins/`
|
|
27
|
+
- 自由にカスタマイズ可能
|
|
28
|
+
|
|
29
|
+
## プラグインの作成
|
|
30
|
+
|
|
31
|
+
### ステップ1: ディレクトリの準備
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# プラグインディレクトリを作成
|
|
35
|
+
mkdir -p ~/.beniya/plugins
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### ステップ2: プラグインファイルの作成
|
|
39
|
+
|
|
40
|
+
`~/.beniya/plugins/my_plugin.rb`を作成:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
# frozen_string_literal: true
|
|
44
|
+
|
|
45
|
+
module Beniya
|
|
46
|
+
module Plugins
|
|
47
|
+
class MyPlugin < Plugin
|
|
48
|
+
# プラグイン名(必須)
|
|
49
|
+
def name
|
|
50
|
+
"MyPlugin"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# 説明(オプション)
|
|
54
|
+
def description
|
|
55
|
+
"私のカスタムプラグイン"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# バージョン(オプション)
|
|
59
|
+
def version
|
|
60
|
+
"1.0.0"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# コマンドの定義(オプション)
|
|
64
|
+
def commands
|
|
65
|
+
{
|
|
66
|
+
hello: method(:say_hello)
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def say_hello
|
|
73
|
+
puts "Hello from MyPlugin!"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### ステップ3: プラグインの読み込み
|
|
81
|
+
|
|
82
|
+
Beniyaを起動すると、自動的に`~/.beniya/plugins/`内のプラグインが読み込まれます。
|
|
83
|
+
|
|
84
|
+
## プラグインの設定
|
|
85
|
+
|
|
86
|
+
### 設定ファイルの作成
|
|
87
|
+
|
|
88
|
+
`~/.beniya/config.yml`:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
plugins:
|
|
92
|
+
# プラグイン名を小文字で指定
|
|
93
|
+
myplugin:
|
|
94
|
+
enabled: true
|
|
95
|
+
|
|
96
|
+
# 無効化したいプラグイン
|
|
97
|
+
fileoperations:
|
|
98
|
+
enabled: false
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 設定のルール
|
|
102
|
+
|
|
103
|
+
- **プラグイン名**: 大文字小文字を区別せず、小文字に統一されます
|
|
104
|
+
- `MyPlugin`, `myplugin`, `MYPLUGIN` → すべて `myplugin` として扱われます
|
|
105
|
+
- **デフォルト**: 設定に記載のないプラグインは**有効**です
|
|
106
|
+
- **enabled**: `true`で有効、`false`で無効
|
|
107
|
+
|
|
108
|
+
## 高度な機能
|
|
109
|
+
|
|
110
|
+
### 外部gemへの依存
|
|
111
|
+
|
|
112
|
+
プラグインが外部gemに依存する場合、`requires`を使用:
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
module Beniya
|
|
116
|
+
module Plugins
|
|
117
|
+
class AdvancedPlugin < Plugin
|
|
118
|
+
# 依存するgemを宣言
|
|
119
|
+
requires 'httparty', 'nokogiri'
|
|
120
|
+
|
|
121
|
+
def name
|
|
122
|
+
"AdvancedPlugin"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def description
|
|
126
|
+
"HTTPartyとNokogiriを使用"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private
|
|
130
|
+
|
|
131
|
+
def fetch_and_parse
|
|
132
|
+
require 'httparty'
|
|
133
|
+
require 'nokogiri'
|
|
134
|
+
|
|
135
|
+
response = HTTParty.get('https://example.com')
|
|
136
|
+
doc = Nokogiri::HTML(response.body)
|
|
137
|
+
# 処理...
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
gemが不足している場合、以下のメッセージが表示されます:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
⚠️ Plugin 'AdvancedPlugin' は以下のgemに依存していますが、インストールされていません:
|
|
148
|
+
- httparty
|
|
149
|
+
- nokogiri
|
|
150
|
+
|
|
151
|
+
以下のコマンドでインストールしてください:
|
|
152
|
+
gem install httparty nokogiri
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### コマンドの定義
|
|
156
|
+
|
|
157
|
+
プラグインは複数のコマンドを提供できます:
|
|
158
|
+
|
|
159
|
+
```ruby
|
|
160
|
+
def commands
|
|
161
|
+
{
|
|
162
|
+
search: method(:search_files),
|
|
163
|
+
count: method(:count_files),
|
|
164
|
+
list: method(:list_files)
|
|
165
|
+
}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
private
|
|
169
|
+
|
|
170
|
+
def search_files
|
|
171
|
+
# 検索処理
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def count_files
|
|
175
|
+
# カウント処理
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def list_files
|
|
179
|
+
# 一覧表示
|
|
180
|
+
end
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## プラグインの例
|
|
184
|
+
|
|
185
|
+
### 1. ファイル検索プラグイン
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
module Beniya
|
|
189
|
+
module Plugins
|
|
190
|
+
class FileSearchPlugin < Plugin
|
|
191
|
+
def name
|
|
192
|
+
"FileSearch"
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def description
|
|
196
|
+
"ファイル名で検索"
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def commands
|
|
200
|
+
{
|
|
201
|
+
search: method(:search_files),
|
|
202
|
+
find_ext: method(:find_by_extension)
|
|
203
|
+
}
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
private
|
|
207
|
+
|
|
208
|
+
def search_files(query = "*")
|
|
209
|
+
Dir.glob("**/*#{query}*").each do |file|
|
|
210
|
+
puts file if File.file?(file)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def find_by_extension(ext)
|
|
215
|
+
Dir.glob("**/*.#{ext}").each do |file|
|
|
216
|
+
puts file
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 2. Git統合プラグイン
|
|
225
|
+
|
|
226
|
+
```ruby
|
|
227
|
+
module Beniya
|
|
228
|
+
module Plugins
|
|
229
|
+
class GitPlugin < Plugin
|
|
230
|
+
def name
|
|
231
|
+
"Git"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def description
|
|
235
|
+
"Git操作の統合"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def commands
|
|
239
|
+
{
|
|
240
|
+
status: method(:git_status),
|
|
241
|
+
branch: method(:current_branch),
|
|
242
|
+
log: method(:git_log)
|
|
243
|
+
}
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
private
|
|
247
|
+
|
|
248
|
+
def git_status
|
|
249
|
+
system('git status') if git_available?
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def current_branch
|
|
253
|
+
if git_available?
|
|
254
|
+
branch = `git branch --show-current`.strip
|
|
255
|
+
puts "ブランチ: #{branch}"
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def git_log
|
|
260
|
+
system('git log --oneline -10') if git_available?
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def git_available?
|
|
264
|
+
if system('which git > /dev/null 2>&1')
|
|
265
|
+
true
|
|
266
|
+
else
|
|
267
|
+
puts "⚠️ gitがインストールされていません"
|
|
268
|
+
false
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 3. システム情報プラグイン
|
|
277
|
+
|
|
278
|
+
```ruby
|
|
279
|
+
module Beniya
|
|
280
|
+
module Plugins
|
|
281
|
+
class SystemInfoPlugin < Plugin
|
|
282
|
+
def name
|
|
283
|
+
"SystemInfo"
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def description
|
|
287
|
+
"システム情報を表示"
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def commands
|
|
291
|
+
{
|
|
292
|
+
info: method(:show_system_info),
|
|
293
|
+
disk: method(:show_disk_usage)
|
|
294
|
+
}
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
private
|
|
298
|
+
|
|
299
|
+
def show_system_info
|
|
300
|
+
puts "OS: #{RbConfig::CONFIG['host_os']}"
|
|
301
|
+
puts "Ruby: #{RUBY_VERSION}"
|
|
302
|
+
puts "ホームディレクトリ: #{ENV['HOME']}"
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def show_disk_usage
|
|
306
|
+
puts "ディスク使用量:"
|
|
307
|
+
system('df -h .')
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## プラグインの仕組み
|
|
315
|
+
|
|
316
|
+
### 自動登録
|
|
317
|
+
|
|
318
|
+
プラグインは`Beniya::Plugin`を継承すると、自動的に`PluginManager`に登録されます:
|
|
319
|
+
|
|
320
|
+
```ruby
|
|
321
|
+
class MyPlugin < Plugin
|
|
322
|
+
# 継承した時点で自動登録される
|
|
323
|
+
end
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### 初期化時の依存チェック
|
|
327
|
+
|
|
328
|
+
プラグインがインスタンス化されるとき、`requires`で宣言したgemがインストールされているかチェックされます:
|
|
329
|
+
|
|
330
|
+
```ruby
|
|
331
|
+
def initialize
|
|
332
|
+
check_dependencies! # 自動的に呼ばれる
|
|
333
|
+
end
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## トラブルシューティング
|
|
337
|
+
|
|
338
|
+
### プラグインが読み込まれない
|
|
339
|
+
|
|
340
|
+
**症状**: プラグインを作成したのに動作しない
|
|
341
|
+
|
|
342
|
+
**確認事項**:
|
|
343
|
+
1. ファイルの場所: `~/.beniya/plugins/` に配置されているか
|
|
344
|
+
2. ファイル名: `.rb`拡張子がついているか
|
|
345
|
+
3. 構文エラー: Rubyの構文が正しいか
|
|
346
|
+
4. 設定ファイル: `config.yml`で無効化されていないか
|
|
347
|
+
|
|
348
|
+
### 依存gemが見つからない
|
|
349
|
+
|
|
350
|
+
**症状**: プラグイン起動時にエラーが出る
|
|
351
|
+
|
|
352
|
+
**解決方法**:
|
|
353
|
+
```bash
|
|
354
|
+
# エラーメッセージに表示されたgemをインストール
|
|
355
|
+
gem install <gem名>
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### プラグインが無効化されている
|
|
359
|
+
|
|
360
|
+
**症状**: プラグインが読み込まれない(エラーなし)
|
|
361
|
+
|
|
362
|
+
**確認**: `~/.beniya/config.yml`を確認
|
|
363
|
+
|
|
364
|
+
```yaml
|
|
365
|
+
plugins:
|
|
366
|
+
myplugin:
|
|
367
|
+
enabled: false # ← これを true に変更
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## ベストプラクティス
|
|
371
|
+
|
|
372
|
+
### 1. わかりやすい名前をつける
|
|
373
|
+
|
|
374
|
+
```ruby
|
|
375
|
+
def name
|
|
376
|
+
"MyAwesomePlugin" # 明確で分かりやすい名前
|
|
377
|
+
end
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### 2. 説明を書く
|
|
381
|
+
|
|
382
|
+
```ruby
|
|
383
|
+
def description
|
|
384
|
+
"このプラグインは〇〇の機能を提供します"
|
|
385
|
+
end
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### 3. エラーハンドリング
|
|
389
|
+
|
|
390
|
+
```ruby
|
|
391
|
+
def my_command
|
|
392
|
+
# エラーが起きる可能性のある処理
|
|
393
|
+
result = some_operation
|
|
394
|
+
rescue StandardError => e
|
|
395
|
+
puts "⚠️ エラーが発生しました: #{e.message}"
|
|
396
|
+
end
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### 4. 外部コマンドの確認
|
|
400
|
+
|
|
401
|
+
```ruby
|
|
402
|
+
def command_available?(cmd)
|
|
403
|
+
system("which #{cmd} > /dev/null 2>&1")
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
def my_feature
|
|
407
|
+
unless command_available?('git')
|
|
408
|
+
puts "⚠️ gitがインストールされていません"
|
|
409
|
+
return
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
# 処理...
|
|
413
|
+
end
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## 参考
|
|
417
|
+
|
|
418
|
+
- サンプルプラグイン: `docs/plugin_example.rb`
|
|
419
|
+
- 組み込みプラグイン: `lib/beniya/plugins/file_operations.rb`
|
|
420
|
+
- プラグイン基底クラス: `lib/beniya/plugin.rb`
|
|
421
|
+
- プラグインマネージャー: `lib/beniya/plugin_manager.rb`
|
|
422
|
+
|
|
423
|
+
## まとめ
|
|
424
|
+
|
|
425
|
+
1. `~/.beniya/plugins/` にRubyファイルを作成
|
|
426
|
+
2. `Beniya::Plugin`を継承したクラスを定義
|
|
427
|
+
3. 必須メソッド`name`を実装
|
|
428
|
+
4. オプションで`description`、`version`、`commands`を実装
|
|
429
|
+
5. Beniya起動時に自動読み込み
|
|
430
|
+
|
|
431
|
+
プラグインシステムを使って、Beniyaを自分好みにカスタマイズしてください!
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Beniya プラグイン実装例
|
|
4
|
+
# このファイルを ~/.beniya/plugins/ にコピーして使用してください
|
|
5
|
+
|
|
6
|
+
module Beniya
|
|
7
|
+
module Plugins
|
|
8
|
+
# ファイル検索プラグインの例
|
|
9
|
+
class FileSearchPlugin < Plugin
|
|
10
|
+
def name
|
|
11
|
+
"FileSearch"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def description
|
|
15
|
+
"ファイル名で検索する機能"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def version
|
|
19
|
+
"1.0.0"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def commands
|
|
23
|
+
{
|
|
24
|
+
search: method(:search_files),
|
|
25
|
+
find_by_ext: method(:find_by_extension)
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
# ファイル名で検索
|
|
32
|
+
def search_files(query)
|
|
33
|
+
Dir.glob("**/*#{query}*").each do |file|
|
|
34
|
+
puts file
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# 拡張子でファイルを検索
|
|
39
|
+
def find_by_extension(ext)
|
|
40
|
+
Dir.glob("**/*.#{ext}").each do |file|
|
|
41
|
+
puts file
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Git統合プラグインの例(外部gem依存)
|
|
47
|
+
class GitIntegrationPlugin < Plugin
|
|
48
|
+
# gitコマンドが必要
|
|
49
|
+
# requires 'git' # gemが必要な場合
|
|
50
|
+
|
|
51
|
+
def name
|
|
52
|
+
"GitIntegration"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def description
|
|
56
|
+
"Git操作を統合"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def commands
|
|
60
|
+
{
|
|
61
|
+
git_status: method(:show_git_status),
|
|
62
|
+
git_branch: method(:show_current_branch)
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def show_git_status
|
|
69
|
+
if system('which git > /dev/null 2>&1')
|
|
70
|
+
system('git status')
|
|
71
|
+
else
|
|
72
|
+
puts "⚠️ gitがインストールされていません"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def show_current_branch
|
|
77
|
+
if system('which git > /dev/null 2>&1')
|
|
78
|
+
branch = `git branch --show-current`.strip
|
|
79
|
+
puts "現在のブランチ: #{branch}"
|
|
80
|
+
else
|
|
81
|
+
puts "⚠️ gitがインストールされていません"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# シンプルなユーティリティプラグイン
|
|
87
|
+
class UtilityPlugin < Plugin
|
|
88
|
+
def name
|
|
89
|
+
"Utility"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def description
|
|
93
|
+
"便利なユーティリティ機能"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def commands
|
|
97
|
+
{
|
|
98
|
+
disk_usage: method(:show_disk_usage),
|
|
99
|
+
count_files: method(:count_files_in_directory)
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def show_disk_usage
|
|
106
|
+
puts "ディスク使用量:"
|
|
107
|
+
system('df -h .')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def count_files_in_directory
|
|
111
|
+
files = Dir.glob('*').select { |f| File.file?(f) }
|
|
112
|
+
dirs = Dir.glob('*').select { |f| File.directory?(f) }
|
|
113
|
+
|
|
114
|
+
puts "ファイル数: #{files.count}"
|
|
115
|
+
puts "ディレクトリ数: #{dirs.count}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Beniya
|
|
4
|
+
# コマンドモード - プラグインコマンドを実行するためのインターフェース
|
|
5
|
+
class CommandMode
|
|
6
|
+
def initialize
|
|
7
|
+
@commands = {}
|
|
8
|
+
load_plugin_commands
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# コマンドを実行する
|
|
12
|
+
def execute(command_string)
|
|
13
|
+
# 空のコマンドは無視
|
|
14
|
+
return nil if command_string.nil? || command_string.strip.empty?
|
|
15
|
+
|
|
16
|
+
# コマンド名を取得 (前後の空白を削除)
|
|
17
|
+
command_name = command_string.strip.to_sym
|
|
18
|
+
|
|
19
|
+
# コマンドが存在するかチェック
|
|
20
|
+
unless @commands.key?(command_name)
|
|
21
|
+
return "⚠️ コマンドが見つかりません: #{command_name}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# コマンドを実行
|
|
25
|
+
begin
|
|
26
|
+
command_method = @commands[command_name][:method]
|
|
27
|
+
command_method.call
|
|
28
|
+
rescue StandardError => e
|
|
29
|
+
"⚠️ コマンド実行エラー: #{e.message}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# 利用可能なコマンドのリストを取得
|
|
34
|
+
def available_commands
|
|
35
|
+
@commands.keys
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# コマンドの情報を取得
|
|
39
|
+
def command_info(command_name)
|
|
40
|
+
return nil unless @commands.key?(command_name)
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
name: command_name,
|
|
44
|
+
plugin: @commands[command_name][:plugin],
|
|
45
|
+
description: @commands[command_name][:description]
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
# プラグインからコマンドを読み込む
|
|
52
|
+
def load_plugin_commands
|
|
53
|
+
# 有効なプラグインを取得
|
|
54
|
+
enabled_plugins = PluginManager.enabled_plugins
|
|
55
|
+
|
|
56
|
+
# 各プラグインからコマンドを取得
|
|
57
|
+
enabled_plugins.each do |plugin|
|
|
58
|
+
plugin_name = plugin.name
|
|
59
|
+
plugin_commands = plugin.commands
|
|
60
|
+
|
|
61
|
+
# 各コマンドを登録
|
|
62
|
+
plugin_commands.each do |command_name, command_method|
|
|
63
|
+
@commands[command_name] = {
|
|
64
|
+
method: command_method,
|
|
65
|
+
plugin: plugin_name,
|
|
66
|
+
description: plugin.description
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|