Module: Kreuzberg::CLIProxy
- Defined in:
- lib/kreuzberg/cli_proxy.rb
Defined Under Namespace
Classes: CLIExecutionError, Error, MissingBinaryError
Class Method Summary collapse
-
.call(argv) ⇒ String
Execute the Kreuzberg CLI with given arguments.
-
.find_cli_binary ⇒ Pathname
Find the kreuzberg CLI binary.
-
.lib_path ⇒ Pathname
Get the lib path.
-
.missing_binary_message ⇒ String
Error message when binary is missing.
-
.root_path ⇒ Pathname
Get the root path of the Ruby package.
-
.search_paths(binary_name) ⇒ Array<Pathname>
Search paths for the CLI binary.
Class Method Details
.call(argv) ⇒ String
Execute the Kreuzberg CLI with given arguments
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kreuzberg/cli_proxy.rb', line 37 def call(argv) binary = find_cli_binary args = Array(argv).map(&:to_s) stdout, stderr, status = Open3.capture3(binary.to_s, *args) return stdout if status.success? raise CLIExecutionError.new( "kreuzberg CLI exited with status #{status.exitstatus}", stderr: stderr, status: status.exitstatus ) end |
.find_cli_binary ⇒ Pathname
Find the kreuzberg CLI binary
Searches in multiple locations:
-
crates/kreuzberg-cli/target/release/
-
packages/ruby/lib/bin/
-
workspace root target/release/
60 61 62 63 64 65 66 |
# File 'lib/kreuzberg/cli_proxy.rb', line 60 def find_cli_binary binary_name = Gem.win_platform? ? 'kreuzberg.exe' : 'kreuzberg' found = search_paths(binary_name).find(&:file?) return found if found raise MissingBinaryError, end |
.lib_path ⇒ Pathname
Get the lib path
80 81 82 |
# File 'lib/kreuzberg/cli_proxy.rb', line 80 def lib_path @lib_path ||= Pathname(__dir__ || '.').join('..'). end |
.missing_binary_message ⇒ String
Error message when binary is missing
109 110 111 112 113 114 115 116 |
# File 'lib/kreuzberg/cli_proxy.rb', line 109 def <<~MSG.strip kreuzberg CLI binary not found. Build it with: `cargo build --release --package kreuzberg-cli` Or install the gem with pre-built binaries. MSG end |
.root_path ⇒ Pathname
Get the root path of the Ruby package
72 73 74 |
# File 'lib/kreuzberg/cli_proxy.rb', line 72 def root_path @root_path ||= Pathname(__dir__ || '.').join('../..'). end |
.search_paths(binary_name) ⇒ Array<Pathname>
Search paths for the CLI binary
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/kreuzberg/cli_proxy.rb', line 89 def search_paths(binary_name) paths = [ lib_path.join('bin', binary_name), lib_path.join(binary_name), root_path.join('../../crates/kreuzberg-cli/target/release', binary_name), root_path.join('../../target/release', binary_name), root_path.join('../../target/debug', binary_name) ] workspace_root = root_path.parent&.parent paths << workspace_root.join('target', 'release', binary_name) if workspace_root paths << workspace_root.join('target', 'debug', binary_name) if workspace_root paths end |