Sha256: 433a893d55fb177be241a45943612cf9608364bc745a70f05a0699f68d06bf28

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require 'thor'

require 'attractor'

module Attractor
  # contains methods implementing the CLI
  class CLI < Thor
    desc 'calc', 'Calculates churn and complexity for all ruby files in current directory'
    option :file_prefix, aliases: :p
    option :watch, aliases: :w, type: :boolean
    def calc
      if options[:watch]
        puts 'Listening for file changes...'
        Attractor::ConsoleReporter.new(file_prefix: options[:file_prefix]).watch
      else
        Attractor::ConsoleReporter.new(file_prefix: options[:file_prefix]).report
      end
    end

    desc 'report', 'Generates an HTML report'
    option :format, aliases: :f, default: 'html'
    option :file_prefix, aliases: :p
    option :watch, aliases: :w, type: :boolean
    def report
      if options[:watch]
        puts 'Listening for file changes...'
        Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).watch
      else
        case options[:format]
        when 'html'
          Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).report
        else
          Attractor::HtmlReporter.new(file_prefix: options[:file_prefix]).report
        end
      end
    end

    desc 'serve', 'Serves the report on localhost'
    option :format, aliases: :f, default: 'html'
    option :file_prefix, aliases: :p
    option :watch, aliases: :w, type: :boolean
    def serve
      if options[:watch]
        puts 'Listening for file changes...'
        Attractor::SinatraReporter.new(file_prefix: options[:file_prefix]).watch
      else
        case options[:format]
        when 'html'
          Attractor::SinatraReporter.new(file_prefix: options[:file_prefix]).report
        else
          Attractor::SinatraReporter.new(file_prefix: options[:file_prefix]).report
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
attractor-0.6.1 lib/attractor/cli.rb
attractor-0.6.0 lib/attractor/cli.rb
attractor-0.5.1 lib/attractor/cli.rb
attractor-0.5.0 lib/attractor/cli.rb
attractor-0.4.3 lib/attractor/cli.rb
attractor-0.4.2 lib/attractor/cli.rb
attractor-0.4.1 lib/attractor/cli.rb
attractor-0.4.0 lib/attractor/cli.rb
attractor-0.3.4 lib/attractor/cli.rb
attractor-0.3.3 lib/attractor/cli.rb