Class: RosettAi::Thor::Tasks::Engines
- Inherits:
-
Thor
- Object
- Thor
- RosettAi::Thor::Tasks::Engines
- Defined in:
- lib/rosett_ai/thor/tasks/engines.rb
Overview
Thor task for engine detection and management
Instance Method Summary collapse
-
#detect ⇒ Array<Hash>
Detect available engines on the system.
-
#list ⇒ void
List available items.
-
#plugins ⇒ void
List installed engine plugins.
-
#status ⇒ String
Return the current status.
Instance Method Details
#detect ⇒ Array<Hash>
Detect available engines on the system.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rosett_ai/thor/tasks/engines.rb', line 58 def detect rows = RosettAi::Engines::Registry.available.filter_map do |name| manifest = RosettAi::Engines::Registry.manifest(name) next unless manifest.dig('components', 'detector') result = build_detector(name).detect result[:checks].map do |check| status = check[:passed] ? Rainbow(t('found')).green : Rainbow(t('not_found')).red [result[:display_name], check[:type], check[:name], status] end rescue StandardError => e [[name, 'manifest', '-', Rainbow("error: #{e.}").red]] end.flatten(1) table = ::Terminal::Table.new( title: Rainbow(t('detect_title')).bright, headings: [t('engine'), t('check_type'), t('check_name'), t('status')], rows: rows, style: { border: :unicode_round } ) puts table end |
#list ⇒ void
This method returns an undefined value.
List available items.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rosett_ai/thor/tasks/engines.rb', line 28 def list rows = RosettAi::Engines::Registry.available.map do |name| manifest = RosettAi::Engines::Registry.manifest(name) [manifest['name'], manifest['display_name'], manifest['version']] rescue StandardError => e [name, Rainbow("error: #{e.}").red, '?'] end table = ::Terminal::Table.new( title: Rainbow(t('list_title')).bright, headings: [t('name'), t('display_name'), t('version')], rows: rows, style: { border: :unicode_round } ) puts table end |
#plugins ⇒ void
This method returns an undefined value.
List installed engine plugins.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rosett_ai/thor/tasks/engines.rb', line 131 def plugins plugin_engines = RosettAi::Plugins::Registry.available(:engine) if plugin_engines.empty? puts Rainbow(t('no_plugins')).yellow return end rows = plugin_engines.map do |name| plugin = RosettAi::Plugins::Registry.plugin_module(:engine, name) version = plugin.respond_to?(:version) ? plugin.version : '?' display = plugin.respond_to?(:display_name) ? plugin.display_name : name [name, display, version] end table = ::Terminal::Table.new( title: Rainbow(t('plugins_title')).bright, headings: [t('name'), t('display_name'), t('version')], rows: rows, style: { border: :unicode_round } ) puts table end |
#status ⇒ String
Return the current status.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rosett_ai/thor/tasks/engines.rb', line 94 def status default_engine = RosettAi.rai_config.default_engine puts "#{t('default_engine')}: #{Rainbow(default_engine).bright}" puts rows = RosettAi::Engines::Registry.available.map do |name| manifest = RosettAi::Engines::Registry.manifest(name) detected = if manifest.dig('components', 'detector') result = build_detector(name).detect result[:detected] ? Rainbow(t('yes')).green : Rainbow(t('no')).red else Rainbow(t('no_detector')).yellow end is_default = name == default_engine ? Rainbow(t('yes')).green : t('no') [manifest['display_name'], detected, is_default] rescue StandardError => e [name, Rainbow("error: #{e.}").red, '?'] end table = ::Terminal::Table.new( title: Rainbow(t('status_title')).bright, headings: [t('engine'), t('detected'), t('default')], rows: rows, style: { border: :unicode_round } ) puts table end |