rufio 0.10.0 → 0.20.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.
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'fileutils'
5
+ require 'shellwords'
6
+
7
+ module Rufio
8
+ # プロジェクトコマンド - 登録されたコマンドを実行する
9
+ class ProjectCommand
10
+ def initialize(log_dir, scripts_dir = nil)
11
+ @log_dir = log_dir
12
+ @scripts_dir = scripts_dir || ConfigLoader.scripts_dir
13
+ @registered_commands = {}
14
+
15
+ # スクリプトディレクトリが存在しなければ作成
16
+ ensure_scripts_directory
17
+ end
18
+
19
+ # コマンドを実行する
20
+ # @param command [String] 実行するコマンド
21
+ # @param working_dir [String] 作業ディレクトリ
22
+ # @return [Hash] 実行結果 { success: Boolean, output: String, error: String }
23
+ def execute(command, working_dir)
24
+ begin
25
+ stdout, stderr, status = Open3.capture3(command, chdir: working_dir)
26
+
27
+ {
28
+ success: status.success?,
29
+ output: stdout,
30
+ error: stderr
31
+ }
32
+ rescue StandardError => e
33
+ {
34
+ success: false,
35
+ output: '',
36
+ error: "Command not found or failed to execute: #{e.message}"
37
+ }
38
+ end
39
+ end
40
+
41
+ # 登録されたコマンドを実行する
42
+ # @param command_name [String] コマンド名
43
+ # @param working_dir [String] 作業ディレクトリ
44
+ # @return [Hash] 実行結果
45
+ def execute_registered(command_name, working_dir)
46
+ unless @registered_commands.key?(command_name)
47
+ return {
48
+ success: false,
49
+ output: '',
50
+ error: "Command '#{command_name}' not found in registered commands"
51
+ }
52
+ end
53
+
54
+ command = @registered_commands[command_name]
55
+ execute(command, working_dir)
56
+ end
57
+
58
+ # コマンドを登録する
59
+ # @param name [String] コマンド名
60
+ # @param command [String] コマンド文字列
61
+ def register(name, command)
62
+ @registered_commands[name] = command
63
+ end
64
+
65
+ # 登録されているコマンドの一覧を取得
66
+ # @return [Array<String>] コマンド名の配列
67
+ def list_registered_commands
68
+ @registered_commands.keys
69
+ end
70
+
71
+ # 左画面用の表示データを取得
72
+ # @return [Array<String>] コマンド名の配列
73
+ def get_left_pane_data
74
+ @registered_commands.keys.map.with_index(1) do |name, index|
75
+ "#{index}. #{name}"
76
+ end
77
+ end
78
+
79
+ # スクリプトディレクトリ内のRubyスクリプト一覧を取得
80
+ # @return [Array<String>] スクリプトファイル名の配列
81
+ def list_scripts
82
+ return [] unless Dir.exist?(@scripts_dir)
83
+
84
+ Dir.glob(File.join(@scripts_dir, '*.rb')).map do |path|
85
+ File.basename(path)
86
+ end.sort
87
+ end
88
+
89
+ # スクリプトを実行する
90
+ # @param script_name [String] スクリプトファイル名
91
+ # @param working_dir [String] 作業ディレクトリ
92
+ # @return [Hash] 実行結果
93
+ def execute_script(script_name, working_dir)
94
+ script_path = File.join(@scripts_dir, script_name)
95
+
96
+ unless File.exist?(script_path)
97
+ return {
98
+ success: false,
99
+ output: '',
100
+ error: "Script not found: #{script_name}"
101
+ }
102
+ end
103
+
104
+ # Rubyスクリプトとして実行
105
+ execute("ruby #{script_path.shellescape}", working_dir)
106
+ end
107
+
108
+ # スクリプトディレクトリのパスを取得
109
+ # @return [String] スクリプトディレクトリのパス
110
+ def scripts_dir
111
+ @scripts_dir
112
+ end
113
+
114
+ private
115
+
116
+ # スクリプトディレクトリを確保する
117
+ def ensure_scripts_directory
118
+ return if Dir.exist?(@scripts_dir)
119
+
120
+ FileUtils.mkdir_p(@scripts_dir)
121
+
122
+ # サンプルスクリプトを作成
123
+ create_sample_script
124
+ end
125
+
126
+ # サンプルスクリプトを作成
127
+ def create_sample_script
128
+ sample_script = File.join(@scripts_dir, 'hello.rb')
129
+ return if File.exist?(sample_script)
130
+
131
+ File.write(sample_script, <<~RUBY)
132
+ #!/usr/bin/env ruby
133
+ # Sample script for rufio project mode
134
+ # This script will be executed in the selected project directory
135
+
136
+ puts "Hello from rufio script!"
137
+ puts "Current directory: \#{Dir.pwd}"
138
+ puts "Files in directory:"
139
+ Dir.glob('*').each do |file|
140
+ puts " - \#{file}"
141
+ end
142
+ RUBY
143
+
144
+ File.chmod(0755, sample_script)
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'time'
5
+
6
+ module Rufio
7
+ # プロジェクトログ - コマンド実行ログを管理する
8
+ class ProjectLog
9
+ def initialize(log_dir)
10
+ @log_dir = log_dir
11
+ FileUtils.mkdir_p(@log_dir) unless Dir.exist?(@log_dir)
12
+ end
13
+
14
+ # ログを保存する
15
+ # @param project_name [String] プロジェクト名
16
+ # @param command [String] 実行したコマンド
17
+ # @param output [String] コマンドの出力
18
+ # @return [String] 保存したログファイルのパス
19
+ def save(project_name, command, output)
20
+ timestamp = Time.now.strftime('%Y%m%d_%H%M%S')
21
+ log_filename = "#{project_name}_#{timestamp}.log"
22
+ log_path = File.join(@log_dir, log_filename)
23
+
24
+ log_content = <<~LOG
25
+ Project: #{project_name}
26
+ Command: #{command}
27
+ Timestamp: #{Time.now}
28
+
29
+ Output:
30
+ #{output}
31
+ LOG
32
+
33
+ File.write(log_path, log_content)
34
+ log_path
35
+ end
36
+
37
+ # ログディレクトリに移動する
38
+ # @return [Hash] ログディレクトリ情報
39
+ def navigate_to_log_dir
40
+ {
41
+ path: @log_dir
42
+ }
43
+ end
44
+
45
+ # ログファイルの一覧を取得(新しい順)
46
+ # @return [Array<String>] ログファイル名の配列
47
+ def list_log_files
48
+ log_files = Dir.glob(File.join(@log_dir, '*.log'))
49
+
50
+ # ファイルの更新時刻でソート(新しい順)
51
+ log_files.sort_by { |f| -File.mtime(f).to_i }
52
+ .map { |f| File.basename(f) }
53
+ end
54
+
55
+ # ログファイルのプレビューを取得
56
+ # @param filename [String] ログファイル名
57
+ # @return [String] ログファイルの内容
58
+ def preview(filename)
59
+ log_path = File.join(@log_dir, filename)
60
+
61
+ return '' unless File.exist?(log_path)
62
+
63
+ File.read(log_path)
64
+ rescue StandardError
65
+ ''
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rufio
4
+ # プロジェクトモード - ブックマークしたプロジェクトの管理とコマンド実行
5
+ class ProjectMode
6
+ attr_reader :selected_path, :selected_name
7
+
8
+ def initialize(bookmark, log_dir)
9
+ @bookmark = bookmark
10
+ @log_dir = log_dir
11
+ @active = false
12
+ @selected_path = nil
13
+ @selected_name = nil
14
+ end
15
+
16
+ # プロジェクトモードをアクティブにする
17
+ def activate
18
+ @active = true
19
+ end
20
+
21
+ # プロジェクトモードを非アクティブにする
22
+ def deactivate
23
+ @active = false
24
+ @selected_path = nil
25
+ @selected_name = nil
26
+ end
27
+
28
+ # プロジェクトモードがアクティブかどうか
29
+ def active?
30
+ @active
31
+ end
32
+
33
+ # ブックマーク一覧を取得
34
+ def list_bookmarks
35
+ return [] unless @active
36
+
37
+ @bookmark.list
38
+ end
39
+
40
+ # ブックマークを番号で選択
41
+ def select_bookmark(number)
42
+ return false unless @active
43
+
44
+ bookmark = @bookmark.find_by_number(number)
45
+ return false unless bookmark
46
+
47
+ @selected_path = bookmark[:path]
48
+ @selected_name = bookmark[:name]
49
+ true
50
+ end
51
+
52
+ # 選択をクリア
53
+ def clear_selection
54
+ @selected_path = nil
55
+ @selected_name = nil
56
+ end
57
+ end
58
+ end