Sha256: be16153fde69f8f7dbe91bdcbad32f25bcac203f309c1f7db49999e74414768a

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'mixlib/cli'
require 'sandi_meter/file_scanner'
require 'sandi_meter/formatter'
require 'sandi_meter/logger'
require 'sandi_meter/html_generator'

module SandiMeter
  class CommandParser
    include Mixlib::CLI

    option :path,
      short: "-p PATH",
      long: "--path PATH",
      description: "Path to folder or file to analyze",
      default: "."

    option :log,
      short: "-l",
      long: "--log",
      description: "Show syntax error and indentation log output",
      boolean: true

    option :graph,
      short: "-g",
      long: "--graph",
      description: "Create folder and log data to graph",
      boolean: true

    option :help,
      short: "-h",
      long: "--help",
      description: "Help",
      on: :tail,
      boolean: true,
      show_options: true,
      exit: 0

    option :rules,
      short: "-r",
      long: "--rules",
      description: "Show rules",
      boolean: 0
  end

  class CLI
    def self.execute
      cli = CommandParser.new
      cli.parse_options

      if cli.config[:rules]
        show_sandi_rules
        exit 0
      end

      scanner = SandiMeter::FileScanner.new(cli.config[:log])
      data = scanner.scan(cli.config[:path])
      formatter = SandiMeter::Formatter.new

      formatter.print_data(data)

      if cli.config[:graph]
        logger = SandiMeter::Logger.new
        logger.log!(cli.config[:path], data)

        html_generator = SandiMeter::HtmlGenerator.new
        html_generator.copy_assets!(cli.config[:path])
        html_generator.generate_data!(cli.config[:path])
      end
    end

    def self.show_sandi_rules
      puts %(
        1. 100 lines per class
        2. 5 lines per method
        3. 4 params per method call (and don't even try cheating with hash params)
        4. 1 instance variables per controller' action
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sandi_meter-0.0.6 lib/sandi_meter/cli.rb