Class: RubyDuplicates::CLI

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

Class Method Summary collapse

Class Method Details

.run(argv = ARGV) ⇒ Object



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/ruby_duplicates/cli.rb', line 305

def self.run(argv = ARGV)
  options = {
    threshold: 0.82,
    min_lines: 4,
    min_nodes: 20,
    max_results: 50,
    format: "text",
    ignore_dirs: RubyDuplicates::DEFAULT_IGNORES.dup
  }

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: ruby-duplicates [options] [file-or-directory ...]"

    opts.on("--threshold N", Float, "Minimum structural similarity score, default 0.82") { |value| options[:threshold] = value }
    opts.on("--min-lines N", Integer, "Minimum method source lines, default 4") { |value| options[:min_lines] = value }
    opts.on("--min-nodes N", Integer, "Minimum normalized syntax nodes, default 20") { |value| options[:min_nodes] = value }
    opts.on("--max-results N", Integer, "Maximum matches to print, default 50") { |value| options[:max_results] = value }
    opts.on("--format FORMAT", "text or json, default text") { |value| options[:format] = value }
    opts.on("--json", "Same as --format json") { options[:format] = "json" }
    opts.on("--ignore-dir NAME", "Directory basename or path to skip; may be repeated") { |value| options[:ignore_dirs] << value }
  end

  parser.parse!(argv)
  options[:paths] = argv.empty? ? ["."] : argv

  abort "format must be text or json" unless %w[text json].include?(options[:format])

  RubyDuplicates.new(options).run
end