Class: Harbinger::CLI
- Inherits:
-
Thor
- Object
- Thor
- Harbinger::CLI
- Defined in:
- lib/harbinger/cli.rb
Constant Summary collapse
- ECOSYSTEM_PRIORITY =
Ecosystem priority for determining primary language
%w[ruby python rust go nodejs].freeze
- ECOSYSTEMS =
Ecosystem definitions with languages and databases
{ "ruby" => { name: "Ruby Ecosystem", languages: ["ruby", "rails"], databases: ["postgres", "mysql", "redis", "mongo"] }, "python" => { name: "Python Ecosystem", languages: ["python"], databases: ["postgres", "mysql", "redis", "mongo"] }, "rust" => { name: "Rust Ecosystem", languages: ["rust"], databases: ["postgres", "mysql", "redis", "mongo"] }, "go" => { name: "Go Ecosystem", languages: ["go"], databases: ["postgres", "mysql", "redis", "mongo"] }, "nodejs" => { name: "Node.js Ecosystem", languages: ["nodejs"], databases: ["postgres", "mysql", "redis", "mongo"] } }.freeze
- COMPONENT_DISPLAY_NAMES =
Component display names for table headers
{ "ruby" => "Ruby", "rails" => "Rails", "python" => "Python", "nodejs" => "Node.js", "rust" => "Rust", "go" => "Go", "postgres" => "PostgreSQL", "mysql" => "MySQL", "redis" => "Redis", "mongo" => "MongoDB" }.freeze
- PRODUCT_NAME_MAP =
Product name mapping for EOL API lookups
{ "ruby" => "ruby", "rails" => "rails", "postgres" => "postgresql", "mysql" => "mysql", "redis" => "redis", "mongo" => "mongodb", "python" => "python", "nodejs" => "nodejs", "rust" => "rust", "go" => "go" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #remove(project_name) ⇒ Object
- #rescan ⇒ Object
- #scan ⇒ Object
- #show(project_filter = nil) ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
25 26 27 |
# File 'lib/harbinger/cli.rb', line 25 def self.exit_on_failure? true end |
Instance Method Details
#remove(project_name) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/harbinger/cli.rb', line 194 def remove(project_name) config_manager = ConfigManager.new project = config_manager.get_project(project_name) if project config_manager.remove_project(project_name) say "Removed '#{project_name}' (#{project["path"]})", :green else say "Project '#{project_name}' not found", :yellow say "\nTracked projects:", :cyan config_manager.list_projects.keys.sort.each { |name| say " #{name}" } end end |
#rescan ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/harbinger/cli.rb', line 210 def rescan config_manager = ConfigManager.new projects = config_manager.list_projects if projects.empty? say "No projects tracked yet.", :yellow say "Use 'harbinger scan --save' to add projects", :cyan return end say "Re-scanning #{projects.size} tracked project(s)...\n\n", :cyan updated_count = 0 removed_count = 0 projects.each_with_index do |(name, data), index| project_path = data["path"] unless File.directory?(project_path) say "[#{index + 1}/#{projects.size}] #{name}: Path not found, removing from config", :yellow config_manager.remove_project(name) removed_count += 1 next end if [:verbose] say "=" * 60, :cyan say "[#{index + 1}/#{projects.size}] Re-scanning #{name}", :cyan say "=" * 60, :cyan scan_single(project_path) else say "[#{index + 1}/#{projects.size}] #{name}...", :white # Detect versions quietly ruby_detector = Analyzers::RubyDetector.new(project_path) rails_analyzer = Analyzers::RailsAnalyzer.new(project_path) postgres_detector = Analyzers::PostgresDetector.new(project_path) mysql_detector = Analyzers::MysqlDetector.new(project_path) redis_detector = Analyzers::RedisDetector.new(project_path) mongo_detector = Analyzers::MongoDetector.new(project_path) python_detector = Analyzers::PythonDetector.new(project_path) node_detector = Analyzers::NodeDetector.new(project_path) rust_detector = Analyzers::RustDetector.new(project_path) go_detector = Analyzers::GoDetector.new(project_path) ruby_version = ruby_detector.detect rails_version = rails_analyzer.detect postgres_version = postgres_detector.detect mysql_version = mysql_detector.detect redis_version = redis_detector.detect mongo_version = mongo_detector.detect python_version = python_detector.detect nodejs_version = node_detector.detect rust_version = rust_detector.detect go_version = go_detector.detect # Save to config config_manager.save_project( name: name, path: project_path, versions: { ruby: ruby_version, rails: rails_version, postgres: postgres_version, mysql: mysql_version, redis: redis_version, mongo: mongo_version, python: python_version, nodejs: nodejs_version, rust: rust_version, go: go_version }.compact ) end updated_count += 1 end say "\n✓ Updated #{updated_count} project(s)", :green say "✓ Removed #{removed_count} project(s) with missing directories", :yellow if removed_count.positive? say "\nView updated projects with: harbinger show", :cyan end |
#scan ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/harbinger/cli.rb', line 93 def scan project_path = File.([:path] || Dir.pwd) unless File.directory?(project_path) say "Error: #{project_path} is not a valid directory", :red exit 1 end if [:recursive] scan_recursive(project_path) else scan_single(project_path) end end |
#show(project_filter = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/harbinger/cli.rb', line 112 def show(project_filter = nil) config_manager = ConfigManager.new projects = config_manager.list_projects if projects.empty? say "No projects tracked yet.", :yellow say "Use 'harbinger scan --save' to add projects", :cyan return end # Filter by project name or path if specified if project_filter projects = projects.select do |name, data| name.downcase.include?(project_filter.downcase) || data["path"]&.downcase&.include?(project_filter.downcase) end if projects.empty? say "No projects matching '#{project_filter}'", :yellow return end end # Handle export formats if [:format] != "table" export_data(projects, [:format], [:output]) return end # Group projects by ecosystem fetcher = EolFetcher.new ecosystem_projects = group_projects_by_ecosystem(projects) # Check if any projects have a programming language if ecosystem_projects.empty? say "No projects with detected versions.", :yellow say "Use 'harbinger scan --save' to add projects", :cyan return end # Display header with total project count total_projects = ecosystem_projects.values.sum(&:size) say "Tracked Projects (#{total_projects})", :cyan # Render each ecosystem table ECOSYSTEMS.keys.each do |ecosystem_key| projects_in_ecosystem = ecosystem_projects[ecosystem_key] next if projects_in_ecosystem.empty? # Hide empty tables render_ecosystem_table( ecosystem_key, projects_in_ecosystem, fetcher, verbose: [:verbose] ) end say "\nUse 'harbinger scan --path <project>' to update a project", :cyan end |
#update ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/harbinger/cli.rb', line 173 def update say "Updating EOL data...", :cyan fetcher = EolFetcher.new products = %w[ruby rails postgresql mysql redis mongodb python nodejs rust go] products.each do |product| say "Fetching #{product}...", :white data = fetcher.fetch(product) if data say " ✓ #{product.capitalize}: #{data.length} versions cached", :green else say " ✗ #{product.capitalize}: Failed to fetch", :red end end say "\nEOL data updated successfully!", :green end |
#version ⇒ Object
294 295 296 |
# File 'lib/harbinger/cli.rb', line 294 def version say "Harbinger version #{Harbinger::VERSION}", :cyan end |