Sha256: ed7eb00da6e957c2e182666769544c8e7ea307731d9967ac0c21386ee567473c

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

require 'metric_fu'
require 'metric_fu/cli/parser'
# see https://github.com/grosser/pru/blob/master/bin/pru
module MetricFu
  module Cli
    def self.immediate_shutdown!
      exit(1)
    end
    def self.complete!
      exit(0)
    end
    class Helper
      def initialize
        @metric_fu = MetricFu::Run.new
      end
      def run(options={})
        @metric_fu.run(options)
        complete
      end
      def version
        MetricFu::VERSION
      end
      def shutdown
        out "\nShuting down. Bye"
        MetricFu::Cli.immediate_shutdown!
      end
      def banner
        "MetricFu: A Fistful of code metrics"
      end
      def usage
        <<-EOS
        #{banner}
        Use --help for help
        EOS
      end
      def executable_name
        'metric_fu'
      end

      def metrics
        MetricFu::Metric.metrics.map(&:name).sort_by(&:to_s)
      end

      def process_options(argv=[])
        options = MetricFu::Cli::MicroOptParse::Parser.new do |p|
            p.banner = self.banner
            p.version = self.version
            p.option :run, "Run all metrics with defaults", :default => true
            metrics.each do |metric|
              p.option metric.to_sym, "Enables or disables #{metric.to_s}", :default => true #, :value_in_set => [true, false]
            end
            p.option :open, "Open report in browser (if supported by formatter)", :default => true
        end.process!(argv)
        options
      end

      private
      def out(text)
        STDOUT.puts text
      end
      def error(text)
        STDERR.puts text
      end
      def complete
        out "all done"
        MetricFu::Cli.complete!
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metric_fu-4.6.0 lib/metric_fu/cli/helper.rb
metric_fu-4.5.2 lib/metric_fu/cli/helper.rb
metric_fu-4.5.1 lib/metric_fu/cli/helper.rb