Class: CodeSage::CLI
- Inherits:
-
Thor
- Object
- Thor
- CodeSage::CLI
- Defined in:
- lib/code_sage/cli.rb
Instance Method Summary collapse
Instance Method Details
#config ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/code_sage/cli.rb', line 54 def config config_instance = Config.new if [:show] config_instance.show_config_info puts "š CodeSage Configuration".colorize(:cyan).bold puts "=" * 50 puts YAML.dump(config_instance.data) elsif [:reset] config_instance.reset! puts "ā Configuration reset to defaults".colorize(:green) elsif [:key] && [:value] config_instance.set([:key], [:value]) config_instance.save! puts "ā Configuration updated: #{options[:key]} = #{options[:value]}".colorize(:green) else config_instance.show_config_info puts "Use --show to display configuration" puts "Use --key KEY --value VALUE to update settings" puts "Use --reset to restore defaults" end end |
#diagnose ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 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 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 |
# File 'lib/code_sage/cli.rb', line 78 def diagnose puts "š CodeSage System Diagnostics".colorize(:cyan).bold puts "=" * 50 # Check Ruby version print "Ruby: " puts "ā (#{RUBY_VERSION})".colorize(:green) # Check Git print "Git: " begin git_version = `git --version 2>/dev/null`.strip if $?.success? puts "ā (#{git_version})".colorize(:green) else puts "ā Not found".colorize(:red) end rescue puts "ā Not found".colorize(:red) end # Check llm_chain availability print "LLMChain: " begin require 'llm_chain' puts "ā Available".colorize(:green) # Run llm_chain diagnostics if available if defined?(LLMChain) && LLMChain.respond_to?(:diagnose_system) puts "\nš LLMChain Diagnostics:".colorize(:yellow) LLMChain.diagnose_system end rescue LoadError puts "ā Not available".colorize(:red) puts " Run: gem install llm_chain".colorize(:yellow) end # Check API Keys puts "\nš API Keys:".colorize(:yellow) api_keys = { 'OpenAI' => ENV['OPENAI_API_KEY'], 'Google' => ENV['GOOGLE_API_KEY'], 'Anthropic' => ENV['ANTHROPIC_API_KEY'] } api_keys.each do |name, key| print "#{name}: " if key && !key.empty? puts "ā Configured".colorize(:green) else puts "ā Not set".colorize(:red) end end # Check configuration puts "\nāļø Configuration:".colorize(:yellow) config = Config.new llm_config = config.data['llm'] print "LLM Provider: " puts "#{llm_config['provider'] || 'openai'}".colorize(:cyan) print "Model: " puts "#{llm_config['model'] || 'gpt-4'}".colorize(:cyan) puts "\nš” Recommendations:".colorize(:yellow) recommendations = [] recommendations << "⢠Configure API keys for your chosen LLM provider" unless api_keys.values.any? do |key| key && !key.empty? end if llm_config['provider'] == 'ollama' recommendations << "⢠Install and start Ollama for local models: ollama serve" end recommendations << "⢠Ensure you're in a Git repository for code review" unless Dir.exist?('.git') if recommendations.empty? puts "ā System looks good!".colorize(:green) else recommendations.each { |rec| puts rec } end end |
#review ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/code_sage/cli.rb', line 16 def review puts "š® CodeSage - Wisdom for your code".colorize(:cyan) puts begin reviewer = Reviewer.new( branch: [:branch] || 'main', files: [:files], format: [:format], format_explicit: ARGV.include?('--format') || ARGV.any? { |arg| arg.start_with?('--format=') }, config_path: [:config], verbose: [:verbose], enable_rag: [:rag] || false, auto_fix: [:auto_fix] || false, confirm_fixes: [:confirm_fixes] != false ) result = reviewer.review if result[:success] puts "ā Code review completed successfully!".colorize(:green) else puts "ā Code review failed: #{result[:error]}".colorize(:red) exit 1 end rescue => e puts "š„ Error: #{e.message}".colorize(:red) puts e.backtrace.join("\n").colorize(:yellow) if [:verbose] exit 1 end end |
#version ⇒ Object
163 164 165 |
# File 'lib/code_sage/cli.rb', line 163 def version puts "CodeSage version #{CodeSage::VERSION}" end |