Class: CodeSage::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/code_sage/cli.rb

Instance Method Summary collapse

Instance Method Details

#configObject



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 options[:show]
    config_instance.show_config_info
    puts "šŸ“‹ CodeSage Configuration".colorize(:cyan).bold
    puts "=" * 50
    puts YAML.dump(config_instance.data)
  elsif options[:reset]
    config_instance.reset!
    puts "āœ… Configuration reset to defaults".colorize(:green)
  elsif options[:key] && options[:value]
    config_instance.set(options[:key], options[: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

#diagnoseObject



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

#reviewObject



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: options[:branch] || 'main',
      files: options[:files],
      format: options[:format],
      format_explicit: ARGV.include?('--format') || ARGV.any? { |arg| arg.start_with?('--format=') },
      config_path: options[:config],
      verbose: options[:verbose],
      enable_rag: options[:rag] || false,
      auto_fix: options[:auto_fix] || false,
      confirm_fixes: options[: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 options[:verbose]
    exit 1
  end
end

#versionObject



163
164
165
# File 'lib/code_sage/cli.rb', line 163

def version
  puts "CodeSage version #{CodeSage::VERSION}"
end