Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow flags to be added to configuration in .metrics #236

Open
shawnacscott opened this issue Nov 12, 2014 · 11 comments
Open

Comments

@shawnacscott
Copy link

I'm hoping this is actually not a feature request and I'm just doing it wrong. :)

I would like to add metric_fu to my Rails project which my company runs on a Vagrant instance. Because we're using this VM, I would like to have it always run with the --no-open flag by default so that my team members don't have to remember to either pass the flag or ignore the errors every time. I'd like to be able to do something like:

# .metrics

MetricFu::Configuration.run do |config|
    config.open = false
end

If there's a way to do this that I've missed, I'd love to hear it.

Thanks!

@bf4
Copy link
Member

bf4 commented Nov 12, 2014

So, before answering your specific question, here's a dumb answer

Create the file bin/metric_fu with

#!/usr/bin/env bash
metric_fu --no-open

chmod +x bin/metric_fu

Or if you don't want to chmod, then just bash bin/metric_fu

and now you have a super dumb wrapper around your desired behavior and just tell everyone to use ./bin/metric_fu to run their metrics.

The sad answer is that this appears to only be available as an argument to Run, so it's not a regular config :(

I suppose you could also write your own runner using the interface MetricFu.run or MetricFu.run_only that's used by the rake task but I'm not sure if that might change in the future.

@shawnacscott
Copy link
Author

In case you want it:

{"Ruby"=>
  {"Engine"=>"ruby",
   "Version"=>"2.1.0",
   "Patchlevel"=>0,
   "Ripper Support"=>true,
   "Rubygems Version"=>"2.2.0",
   "Long Description"=>
    "ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]"},
 "Environment"=>
  {"VERBOSE"=>"false",
   "External Encoding"=>"UTF-8",
   "Internal Encoding"=>"",
   "Host Architecture"=>"x86_64-redhat-linux-gnu",
   "Ruby Prefix"=>"/usr",
   "Ruby Options"=>"RUBYOPT=-rbundler/setup"},
 "MetricFu"=>
  {"Version"=>"4.11.1",
   "Verbose Mode"=>false,
   "Enabled Metrics"=>
    [:cane,
     :churn,
     :flay,
     :flog,
     :stats,
     :saikuro,
     :reek,
     :roodi,
     :rails_best_practices,
     :hotspots],
   "Dependencies"=>
    [{"name"=>"flay", "version"=>[">= 2.0.1", "~> 2.1"]},
     {"name"=>"churn", "version"=>["~> 0.0.35"]},
     {"name"=>"flog", "version"=>[">= 4.1.1", "~> 4.1"]},
     {"name"=>"reek", "version"=>[">= 1.3.4", "~> 1.3"]},
     {"name"=>"cane", "version"=>[">= 2.5.2", "~> 2.5"]},
     {"name"=>"rails_best_practices", "version"=>[">= 1.14.3", "~> 1.14"]},
     {"name"=>"saikuro", "version"=>[">= 1.1.3", "~> 1.1"]},
     {"name"=>"roodi", "version"=>["~> 3.1"]},
     {"name"=>"code_metrics", "version"=>["~> 0.1"]},
     {"name"=>"redcard", "version"=>[">= 0"]},
     {"name"=>"coderay", "version"=>[">= 0"]},
     {"name"=>"multi_json", "version"=>[">= 0"]},
     {"name"=>"launchy", "version"=>["~> 2.0"]},
     {"name"=>"rcov", "version"=>["~> 0.8"]}]}}

@bf4
Copy link
Member

bf4 commented Nov 12, 2014

I'd be happy to pair on a PR if you want to.

@shawnacscott
Copy link
Author

Thanks for the info! I'm pretty noob-ish, so I'm not sure how much help I can be, but I'd be happy to pair on this at some point if you're available and have the patience!

@shawnacscott
Copy link
Author

One caveat to your bash script answer is that it will conflict with any generated bundler binstub for metric_fu.

@bf4
Copy link
Member

bf4 commented Nov 12, 2014

Well, if metric_fu is in your Gemfile, then edit the script to bundle exec metric_fu --no-open :)

@bf4
Copy link
Member

bf4 commented Nov 14, 2014

Did that help?

@shawnacscott
Copy link
Author

Unfortunately, no. I'm using the auto generated binstub, which looks like this:

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'metric_fu' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

load Gem.bin_path('metric_fu', 'metric_fu')

It wasn't obvious to me where in this script, if anywhere, I could add a flag as suggested. The docs for Gem.bin_path didn't seem to point to that being an option, either.

@bf4
Copy link
Member

bf4 commented Nov 15, 2014

@shawnacscott Behold:

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'metric_fu' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require 'rubygems'
require 'bundler/setup'

if ARGV.grep(/open/).empty?
  puts "bin/metric_fu is adding the --no-open flag for you"
 ARGV << "--no-open"
end
load Gem.bin_path('metric_fu', 'metric_fu')

@shawnacscott
Copy link
Author

👍 Thanks, works like a charm! Appreciate it!

@bf4
Copy link
Member

bf4 commented Nov 17, 2014

I suppose I should leave this open to document this:

I just remembered that there actually is a config that is totally roundabout and unfortunately separated from the 'open' option.

tl;dr in your .metrics file you can set ENV['CC_BUILD_ARTIFACTS']=tmp/metric_fu, i.e. the directory you want the report to be written to. (tmp/metric_fu by default, but you could change it to any directory)

  1. If options[:open] is true, Run will call display_results
  2. display_results has a guard open_in_browser? that checks ! MetricFu.configuration.is_cruise_control_rb?
  3. So, if it opens when 'not cruise control', then it doesn't open when it is cruise control. is_cruise_control_rb? is super legacy, and just checks !!ENV['CC_BUILD_ARTIFACTS'] which is true when non-nil. So, you could also just set that in the .metrics file.
  4. But wait, that same variable determines where metric_fu creates it's report (tmp/metric_fu by default), so the value you set must be a directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants