Class: RosettAi::Completion::Generator
- Inherits:
-
Object
- Object
- RosettAi::Completion::Generator
- 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.
Constant Summary collapse
- SUPPORTED_SHELLS =
['bash', 'zsh', 'fish'].freeze
Instance Attribute Summary collapse
-
#command_tree ⇒ Hash
readonly
Command tree extracted from Thor CLI.
Instance Method Summary collapse
-
#generate(shell) ⇒ String
Generate a completion script for the given shell.
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
-
#supported?(shell) ⇒ Boolean
Whether the shell is supported.
Constructor Details
#initialize ⇒ Generator
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_tree ⇒ Hash (readonly)
Returns 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.
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.
41 42 43 |
# File 'lib/rosett_ai/completion/generator.rb', line 41 def supported?(shell) SUPPORTED_SHELLS.include?(shell.to_s.downcase) end |