Class: NitPicker::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/nitpicker.rb

Constant Summary collapse

CONFIG_DIR =
File.expand_path('~/.config/nitpicker')
PROMPT_FILE =
File.join(CONFIG_DIR, 'prompt')
REPO_PROMPT_FILE =
'.nitpicker_prompt'

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
17
# File 'lib/nitpicker.rb', line 14

def initialize
  @options = {}
  setup_config_dir
end

Instance Method Details

#parse_optionsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nitpicker.rb', line 19

def parse_options
  require 'optparse'
  
  OptionParser.new do |opts|
    opts.banner = 'Usage: nitpicker [options]
   git show | nitpicker              # Review a specific commit
   git diff HEAD~1 | nitpicker       # Review changes from previous commit
   nitpicker                         # Review staged changes (default)'
    opts.version = VERSION

    opts.on('-h', '--help', 'Show this help message') do
      puts opts
      exit
    end
  end.parse!
end

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nitpicker.rb', line 36

def run
  parse_options
  
  # Check if we have piped input
  if STDIN.tty?
    # Interactive terminal - use git diff of staged changes
    diff = `git diff --staged`
    if diff.empty?
      puts "No changes staged for review."
      exit 1
    end
  else
    # STDIN is redirected - try to read from it
    diff = STDIN.read
    if diff.empty?
      # Empty piped input, fall back to git diff
      diff = `git diff --staged`
      if diff.empty?
        puts "No changes staged for review."
        exit 1
      end
    end
  end

  # Get AI-generated code review
  review = generate_code_review(diff)
  
  # Display the review
  puts review
end