Class: DontRepeatYourself::CLI

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

Constant Summary collapse

DEFAULT_REPORT_DESC =

Define methods for generating a DRY *_rails_report for Rails project where plugin is installed

"display the default plain report"
NETBEANS_REPORT_DESC =
"display the report in the Output window of the Netbeans IDE (Ctrl+4)"
HTML_REPORT_DESC =
"generate an DRY_report.html file in the project root folder"
TEXTMATE_REPORT_DESC =
"to generate an html report with links which open files in the Textmate editor"
FORMATS =
DontRepeatYourself::REPORT_TYPES.map{|format| format.downcase}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



29
30
31
# File 'lib/dont_repeat_yourself/cli.rb', line 29

def initialize
  
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/dont_repeat_yourself/cli.rb', line 26

def options
  @options
end

Class Method Details

.executeObject



15
16
17
# File 'lib/dont_repeat_yourself/cli.rb', line 15

def execute
  parse(ARGV).execute!
end

.parse(args) ⇒ Object



19
20
21
22
23
# File 'lib/dont_repeat_yourself/cli.rb', line 19

def parse(args)
  cli = new
  cli.parse_options!(args)
  cli
end

Instance Method Details

#execute!Object



66
67
68
69
70
71
# File 'lib/dont_repeat_yourself/cli.rb', line 66

def execute!
  ruby_project_reporter = DontRepeatYourself::RubyProjectReporter.new(@options[:basedir])
  ruby_project_reporter.with_threshold_of_duplicate_lines(@options[:threshold]) if @options.has_key?(:threshold)
  ruby_project_reporter.send("with_#{@options[:format]}_reporting") if @options.has_key?(:format)      
  STDOUT.print(ruby_project_reporter.report)
end

#parse_options!(args) ⇒ Object



33
34
35
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
# File 'lib/dont_repeat_yourself/cli.rb', line 33

def parse_options!(args)
  args.extend(OptionParser::Arguable)

  @options = { :basedir => './', :format => 'default' }
  args.options do |opts|
    opts.banner = "Usage: dry-report [options] "
    
    opts.on("-d BASEDIR", "--basedir BASEDIR", "set up the base directory of your ruby project, current directory by default") do |b|
      @options[:basedir] = b
    end
    
    opts.on("-f FORMAT", "--format FORMAT", "report format (default is plain text)",
      "Available formats: #{FORMATS.join(", ")}") do |v|
      unless FORMATS.index(v) 
        STDERR.puts "Invalid format: #{v}\n"
        STDERR.puts opts.help
        exit 1
      end
      @options[:format] = v
    end
            
    opts.on("-t THRESHOLD", "--threshold THRESHOLD", "threshold of duplicate lines") do |t|
      @options[:threshold] = t.to_i
    end
    
    opts.on_tail("--help", "You're looking at it. Any question? http://21croissants.blogspot.com/2008/10/dry.html") do
      puts opts.help
      exit
    end
  end.parse!
        
end