Class: LlmDocsBuilder::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_docs_builder/cli.rb

Overview

Command-line interface for llms-txt gem

Provides commands for generating, transforming, parsing, and validating llms.txt files. All file paths must be specified using flags (-d/–docs) for consistency.

Examples:

Run the CLI

LlmDocsBuilder::CLI.run(['generate', '--docs', './docs', '--output', 'llms.txt'])

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(argv = ARGV) ⇒ Object

Run the CLI with given arguments

Parameters:

  • argv (Array<String>) (defaults to: ARGV)

    command-line arguments (defaults to ARGV)



19
20
21
# File 'lib/llm_docs_builder/cli.rb', line 19

def self.run(argv = ARGV)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object

Execute CLI command with error handling

Parses command-line arguments and delegates to appropriate command handler. Handles all LlmDocsBuilder errors gracefully with user-friendly messages.

Parameters:

  • argv (Array<String>)

    command-line arguments

Raises:

  • (SystemExit)

    exits with status 1 on error



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/llm_docs_builder/cli.rb', line 30

def run(argv)
  options = parse_options(argv)

  case options[:command]
  when 'generate', nil
    generate(options)
  when 'transform'
    transform(options)
  when 'bulk-transform'
    bulk_transform(options)
  when 'compare'
    compare(options)
  when 'parse'
    parse(options)
  when 'validate'
    validate(options)
  when 'version'
    show_version
  else
    puts "Unknown command: #{options[:command]}"
    puts "Run 'llm-docs-builder --help' for usage information"
    exit 1
  end
rescue LlmDocsBuilder::Errors::BaseError => e
  puts "Error: #{e.message}"
  exit 1
rescue StandardError => e
  puts "Unexpected error: #{e.message}"
  puts e.backtrace.join("\n") if options&.fetch(:verbose, false)
  exit 1
end