Class: Serialbench::Cli::RubyBuildCli
- Defined in:
- lib/serialbench/cli/ruby_build_cli.rb
Overview
CLI for managing Ruby-Build definitions
Instance Method Summary collapse
- #cache_info ⇒ Object
- #list(filter = nil) ⇒ Object
- #show(tag) ⇒ Object
- #suggest ⇒ Object
- #update ⇒ Object
- #validate(tag) ⇒ Object
Methods inherited from BaseCli
Instance Method Details
#cache_info ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 183 def cache_info if RubyBuildManager.cache_exists? cache_age = RubyBuildManager.cache_age definitions_count = RubyBuildManager.list_definitions.length say 'Ruby-Build Cache Information:', :green say '=' * 40, :green say "Location: #{RubyBuildManager::CACHE_FILE}", :cyan say "Definitions: #{definitions_count}", :cyan say "Age: #{format_cache_age(cache_age)}", :cyan say 'Status: ✅ Available', :green if cache_age > 7 * 24 * 60 * 60 # 7 days say "\n💡 Cache is older than 7 days, consider updating:", :yellow say ' serialbench ruby-build update', :white end else say 'Ruby-Build Cache Information:', :green say '=' * 40, :green say "Location: #{RubyBuildManager::CACHE_FILE}", :cyan say 'Status: ❌ Not found', :red say "\n📥 Update the cache first:", :yellow say ' serialbench ruby-build update', :white end end |
#list(filter = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 53 def list(filter = nil) definitions = RubyBuildManager.list_definitions(filter: filter) if definitions.empty? if filter say "No Ruby-Build definitions found matching '#{filter}'", :yellow else say 'No Ruby-Build definitions found in cache', :yellow say 'Update the cache first: serialbench ruby-build update', :white end return end # Limit results if there are many limited_definitions = definitions.first([:limit]) say "Ruby-Build Definitions#{filter ? " (filtered by '#{filter}')" : ''}:", :green say '=' * 60, :green limited_definitions.each do |definition| say " #{definition}", :cyan end if definitions.length > [:limit] remaining = definitions.length - [:limit] say "\n... and #{remaining} more definitions", :yellow say 'Use --limit to show more results', :white end say "\nTotal: #{definitions.length} definitions", :white rescue StandardError => e say "❌ Failed to list Ruby-Build definitions: #{e.}", :red say 'Try updating the cache: serialbench ruby-build update', :white exit 1 end |
#show(tag) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 97 def show(tag) definition = RubyBuildManager.show_definition(tag) say "Ruby-Build Definition: #{tag}", :green say '=' * 40, :green say "Tag: #{definition[:tag]}", :cyan say "Available: #{definition[:available] ? '✅ Yes' : '❌ No'}", :cyan say "Source: #{definition[:source]}", :cyan say "Cache file: #{definition[:cache_file]}", :white rescue StandardError => e say "❌ #{e.}", :red say 'Available definitions: serialbench ruby-build list', :white exit 1 end |
#suggest ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 155 def suggest current_ruby = RUBY_VERSION suggested_tag = RubyBuildManager.suggest_current_ruby_tag say "Current Ruby version: #{current_ruby}", :cyan say "Suggested ruby_build_tag: #{suggested_tag}", :green # Validate the suggestion if RubyBuildManager.validate_tag(suggested_tag) say '✅ Suggested tag is valid', :green else say '⚠️ Suggested tag not found in ruby-build definitions', :yellow say 'You may need to update the cache or use a different tag', :white end rescue StandardError => e say "❌ Failed to suggest tag: #{e.}", :red say 'Try updating the cache: serialbench ruby-build update', :white exit 1 end |
#update ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 20 def update say '🔄 Updating Ruby-Build definitions...', :green begin definitions = RubyBuildManager.update_definitions say "✅ Successfully updated #{definitions.length} Ruby-Build definitions", :green say "📁 Cache location: #{RubyBuildManager::CACHE_FILE}", :cyan # Show some examples recent_versions = definitions.select { |d| d.match?(/^3\.[2-4]\.\d+$/) }.last(5) if recent_versions.any? say "\n📋 Recent Ruby versions available:", :white recent_versions.each { |version| say " #{version}", :cyan } end rescue StandardError => e say "❌ Failed to update Ruby-Build definitions: #{e.}", :red exit 1 end end |
#validate(tag) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/serialbench/cli/ruby_build_cli.rb', line 120 def validate(tag) valid = RubyBuildManager.validate_tag(tag) if valid say "✅ Ruby-Build tag '#{tag}' is valid", :green else say "❌ Ruby-Build tag '#{tag}' is not valid", :red # Suggest similar tags definitions = RubyBuildManager.list_definitions similar = definitions.select { |d| d.include?(tag.split('.').first(2).join('.')) }.first(5) if similar.any? say "\n💡 Similar available tags:", :yellow similar.each { |s| say " #{s}", :cyan } end exit 1 end rescue StandardError => e say "❌ Failed to validate tag: #{e.}", :red say 'Try updating the cache: serialbench ruby-build update', :white exit 1 end |