Class: RosettAi::Completion::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/completion/generator.rb

Overview

Extracts command metadata from the Thor CLI registry for completion script generation. This is the single source of truth for all shell completion generators.

Author:

  • hugo

  • claude

Constant Summary collapse

SUPPORTED_SHELLS =
['bash', 'zsh', 'fish'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



20
21
22
# File 'lib/rosett_ai/completion/generator.rb', line 20

def initialize
  @command_tree = extract_command_tree
end

Instance Attribute Details

#command_treeHash (readonly)

Returns command tree extracted from Thor CLI.

Returns:

  • (Hash)

    command tree extracted from Thor CLI



18
19
20
# File 'lib/rosett_ai/completion/generator.rb', line 18

def command_tree
  @command_tree
end

Instance Method Details

#generate(shell) ⇒ String

Generate a completion script for the given shell.

Parameters:

  • shell (String)

    one of 'bash', 'zsh', 'fish'

Returns:

  • (String)

    the completion script content

Raises:



29
30
31
32
33
34
35
36
37
# File 'lib/rosett_ai/completion/generator.rb', line 29

def generate(shell)
  shell = shell.to_s.downcase
  unless SUPPORTED_SHELLS.include?(shell)
    raise RosettAi::Error,
          "Shell #{shell} is not supported — available: #{SUPPORTED_SHELLS.join(', ')}"
  end

  shell_generator_for(shell).generate
end

#supported?(shell) ⇒ Boolean

Returns whether the shell is supported.

Parameters:

  • shell (String)

    shell name

Returns:

  • (Boolean)

    whether the shell is supported



41
42
43
# File 'lib/rosett_ai/completion/generator.rb', line 41

def supported?(shell)
  SUPPORTED_SHELLS.include?(shell.to_s.downcase)
end