Class: Synthra::CLI::Commands::Docs

Inherits:
Object
  • Object
show all
Defined in:
lib/synthra/cli/commands/docs.rb

Overview

CLI command for generating schema documentation

Examples:

Generate docs

$ synthra docs schemas/ --output docs/

Constant Summary collapse

EXIT_SUCCESS =
0
EXIT_ERROR =
1

Instance Method Summary collapse

Constructor Details

#initializeDocs

Returns a new instance of Docs.



15
16
17
# File 'lib/synthra/cli/commands/docs.rb', line 15

def initialize
  # No args needed for this command
end

Instance Method Details

#call(schema_dir, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/synthra/cli/commands/docs.rb', line 19

def call(schema_dir, options)
  unless File.directory?(schema_dir)
    $stderr.puts "✗ Schema directory not found: #{schema_dir}"
    return EXIT_ERROR
  end

  output_dir = options[:output] || "docs"
  title = options[:title] || "Synthra Schema Documentation"

  generate_documentation(schema_dir, output_dir, title)
end

#generate_documentation(schema_dir, output_dir, title) ⇒ Object (private)



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
61
62
63
# File 'lib/synthra/cli/commands/docs.rb', line 33

def generate_documentation(schema_dir, output_dir, title)
  require_relative "../../documentation_generator"
  
  puts "📚 Generating documentation..."
  puts "   Source: #{schema_dir}"
  puts "   Output: #{output_dir}"
  puts ""

  # Load schemas
  registry = Registry.new
  registry.load_dir(schema_dir)

  if registry.names.empty?
    $stderr.puts "✗ No schemas found in #{schema_dir}"
    return EXIT_ERROR
  end

  # Generate docs
  generator = DocumentationGenerator.new(registry, title: title)
  files = generator.generate_html(output_dir)

  puts "✅ Generated #{files.count} documentation files:"
  files.each { |path| puts "   #{path}" }
  puts ""
  puts "   Open #{output_dir}/index.html in your browser"

  EXIT_SUCCESS
rescue StandardError => e
  $stderr.puts "✗ Documentation generation failed: #{e.message}"
  EXIT_ERROR
end