Module: Kreuzberg::CLI

Defined in:
lib/kreuzberg/cli.rb

Overview

Examples:

Extract a file

Detect file type

Class Method Summary collapse

Class Method Details

.detect(path_or_nil = nil, path: nil) ⇒ String

Detect MIME type of a file using the CLI

Parameters:

  • path_or_nil (String, nil) (defaults to: nil)

    Path to the file (positional, for backward compatibility)

  • path (String) (defaults to: nil)

    Path to the file (keyword argument)

Returns:

  • (String)

    MIME type

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
# File 'lib/kreuzberg/cli.rb', line 33

def detect(path_or_nil = nil, path: nil)
  # Support both positional and keyword argument for path (backward compatibility)
  actual_path = path_or_nil || path
  raise ArgumentError, 'path is required' if actual_path.nil?

  CLIProxy.call(['detect', actual_path]).strip
end

.extract(path_or_nil = nil, path: nil, output: 'text', ocr: false) ⇒ String

Extract content from a file using the CLI

Parameters:

  • path_or_nil (String, nil) (defaults to: nil)

    Path to the file (positional, for backward compatibility)

  • path (String) (defaults to: nil)

    Path to the file (keyword argument)

  • output (String) (defaults to: 'text')

    Output format (“text”, “json”, “markdown”)

  • ocr (Boolean) (defaults to: false)

    Enable OCR

Returns:

  • (String)

    Extracted content

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
# File 'lib/kreuzberg/cli.rb', line 17

def extract(path_or_nil = nil, path: nil, output: 'text', ocr: false)
  # Support both positional and keyword argument for path (backward compatibility)
  actual_path = path_or_nil || path
  raise ArgumentError, 'path is required' if actual_path.nil?

  args = ['extract', actual_path, '--format', output]
  args.push('--ocr', ocr ? 'true' : 'false')
  CLIProxy.call(args)
end

.helpString

Get CLI help text

Returns:

  • (String)

    Help text



53
54
55
# File 'lib/kreuzberg/cli.rb', line 53

def help
  CLIProxy.call(['--help'])
end

.versionString

Get CLI version

Returns:

  • (String)

    Version string



45
46
47
# File 'lib/kreuzberg/cli.rb', line 45

def version
  CLIProxy.call(['--version']).strip
end