Skip to content

Commit

Permalink
Add --verbose-version (-V) flag
Browse files Browse the repository at this point in the history
This addresses the second feature mentioned in standardrb#452. For context,
when debugging a RuboCop issue a user is asked to supply the
output of `rubocop -V`, and this streamlines this process for
standard users.
  • Loading branch information
patrickbrown-dev committed Sep 28, 2022
1 parent 830205c commit 51e755f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
4 changes: 3 additions & 1 deletion lib/standard/merges_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call(argv, standard_yaml)

def separate_argv(argv)
argv.partition do |flag|
["--generate-todo", "--fix", "--no-fix", "--version", "-v", "--help", "-h"].include?(flag)
["--generate-todo", "--fix", "--no-fix", "--version", "-v", "--verbose-version", "-V", "--help", "-h"].include?(flag)
end
end

Expand All @@ -39,6 +39,8 @@ def determine_command(argv)
:help
elsif (argv & ["--version", "-v"]).any?
:version
elsif (argv & ["--verbose-version", "-V"]).any?
:verbose_version
elsif (argv & ["--generate-todo"]).any?
:genignore
else
Expand Down
15 changes: 8 additions & 7 deletions lib/standard/runners/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ def call(config)
Options:
--fix Automatically fix failures where possible
--no-fix Do not automatically fix failures
--format <name> Format output with any RuboCop formatter (e.g. "json")
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
-v, --version Print the version of Standard
-h, --help Print this message
FILE Files to lint [default: ./]
--fix Automatically fix failures where possible
--no-fix Do not automatically fix failures
--format <name> Format output with any RuboCop formatter (e.g. "json")
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
-v, --version Print the version of Standard
-V, --verbose-version Print the version of Standard and its dependencies.
-h, --help Print this message
FILE Files to lint [default: ./]
Standard also forwards most CLI arguments to RuboCop. To see them, run:
Expand Down
14 changes: 14 additions & 0 deletions lib/standard/runners/verbose_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative "rubocop"

module Standard
module Runners
class VerboseVersion
def call(config)
puts <<-MSG.gsub(/^ {10}/, "")
Standard version: #{Standard::VERSION}
RuboCop version: #{RuboCop::Version.version(debug: true)}
MSG
end
end
end
end
15 changes: 8 additions & 7 deletions test/standard/runners/help_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ def test_prints_help
Options:
--fix Automatically fix failures where possible
--no-fix Do not automatically fix failures
--format <name> Format output with any RuboCop formatter (e.g. "json")
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
-v, --version Print the version of Standard
-h, --help Print this message
FILE Files to lint [default: ./]
--fix Automatically fix failures where possible
--no-fix Do not automatically fix failures
--format <name> Format output with any RuboCop formatter (e.g. "json")
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
-v, --version Print the version of Standard
-V, --verbose-version Print the version of Standard and its dependencies.
-h, --help Print this message
FILE Files to lint [default: ./]
Standard also forwards most CLI arguments to RuboCop. To see them, run:
Expand Down
31 changes: 31 additions & 0 deletions test/standard/runners/verbose_version_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative "../../test_helper"

require "standard/runners/verbose_version"

class Standard::Runners::VerboseVersionTest < UnitTest
def setup
@subject = Standard::Runners::VerboseVersion.new
end

def test_verbose_version
fake_out, _ = do_with_fake_io {
@subject.call(nil)
}

expect = <<-EXPECT.gsub(/^ {6}/, "")
Standard version: #{Standard::VERSION}
RuboCop version: #{RuboCop::Version.version(debug: true)}
EXPECT

assert_equal expect, fake_out.string
end

def test_includes_rubocop_sub_dependencies
fake_out, _ = do_with_fake_io {
@subject.call(nil)
}

assert_match(/Parser/, fake_out.string)
assert_match(/rubocop-ast/, fake_out.string)
end
end

0 comments on commit 51e755f

Please sign in to comment.