Skip to content

Commit 635c384

Browse files
Add --verbose-version (-V) flag
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.
1 parent 830205c commit 635c384

File tree

7 files changed

+83
-18
lines changed

7 files changed

+83
-18
lines changed

lib/standard/loads_runner.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1+
require_relative "runners/rubocop"
2+
require_relative "runners/version"
3+
require_relative "runners/verbose_version"
4+
require_relative "runners/help"
5+
16
module Standard
27
class LoadsRunner
3-
# Warning: clever metaprogramming. 99% of the time this is Runners::Rubocop
8+
RUNNERS = {
9+
rubocop: ::Standard::Runners::Rubocop,
10+
version: ::Standard::Runners::Version,
11+
verbose_version: ::Standard::Runners::VerboseVersion,
12+
help: ::Standard::Runners::Help
13+
}.freeze
14+
415
def call(command)
5-
require_relative "runners/#{command}"
6-
::Standard::Runners.const_get(command.to_s.capitalize).new
16+
RUNNERS[command].new
717
end
818
end
919
end

lib/standard/merges_settings.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def call(argv, standard_yaml)
2020

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

@@ -39,6 +39,8 @@ def determine_command(argv)
3939
:help
4040
elsif (argv & ["--version", "-v"]).any?
4141
:version
42+
elsif (argv & ["--verbose-version", "-V"]).any?
43+
:verbose_version
4244
elsif (argv & ["--generate-todo"]).any?
4345
:genignore
4446
else

lib/standard/runners/help.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ def call(config)
99
1010
Options:
1111
12-
--fix Automatically fix failures where possible
13-
--no-fix Do not automatically fix failures
14-
--format <name> Format output with any RuboCop formatter (e.g. "json")
15-
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
16-
-v, --version Print the version of Standard
17-
-h, --help Print this message
18-
FILE Files to lint [default: ./]
12+
--fix Automatically fix failures where possible
13+
--no-fix Do not automatically fix failures
14+
--format <name> Format output with any RuboCop formatter (e.g. "json")
15+
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
16+
-v, --version Print the version of Standard
17+
-V, --verbose-version Print the version of Standard and its dependencies.
18+
-h, --help Print this message
19+
FILE Files to lint [default: ./]
1920
2021
Standard also forwards most CLI arguments to RuboCop. To see them, run:
2122
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require_relative "rubocop"
2+
3+
module Standard
4+
module Runners
5+
class VerboseVersion
6+
def call(config)
7+
puts <<-MSG.gsub(/^ {10}/, "")
8+
Standard version: #{Standard::VERSION}
9+
RuboCop version: #{RuboCop::Version.version(debug: true)}
10+
MSG
11+
end
12+
end
13+
end
14+
end

test/standard/loads_runner_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def test_version
1717
assert_instance_of ::Standard::Runners::Version, result
1818
end
1919

20+
def test_verbose_version
21+
result = @subject.call(:verbose_version)
22+
23+
assert_instance_of ::Standard::Runners::VerboseVersion, result
24+
end
25+
2026
def test_help
2127
result = @subject.call(:help)
2228

test/standard/runners/help_test.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ def test_prints_help
1717
1818
Options:
1919
20-
--fix Automatically fix failures where possible
21-
--no-fix Do not automatically fix failures
22-
--format <name> Format output with any RuboCop formatter (e.g. "json")
23-
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
24-
-v, --version Print the version of Standard
25-
-h, --help Print this message
26-
FILE Files to lint [default: ./]
20+
--fix Automatically fix failures where possible
21+
--no-fix Do not automatically fix failures
22+
--format <name> Format output with any RuboCop formatter (e.g. "json")
23+
--generate-todo Create a .standard_todo.yml that lists all the files that contain errors
24+
-v, --version Print the version of Standard
25+
-V, --verbose-version Print the version of Standard and its dependencies.
26+
-h, --help Print this message
27+
FILE Files to lint [default: ./]
2728
2829
Standard also forwards most CLI arguments to RuboCop. To see them, run:
2930
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require_relative "../../test_helper"
2+
3+
require "standard/runners/verbose_version"
4+
5+
class Standard::Runners::VerboseVersionTest < UnitTest
6+
def setup
7+
@subject = Standard::Runners::VerboseVersion.new
8+
end
9+
10+
def test_verbose_version
11+
fake_out, _ = do_with_fake_io {
12+
@subject.call(nil)
13+
}
14+
15+
expect = <<-EXPECT.gsub(/^ {6}/, "")
16+
Standard version: #{Standard::VERSION}
17+
RuboCop version: #{RuboCop::Version.version(debug: true)}
18+
EXPECT
19+
20+
assert_equal expect, fake_out.string
21+
end
22+
23+
def test_includes_rubocop_sub_dependencies
24+
fake_out, _ = do_with_fake_io {
25+
@subject.call(nil)
26+
}
27+
28+
assert_match(/Parser/, fake_out.string)
29+
assert_match(/rubocop-ast/, fake_out.string)
30+
end
31+
end

0 commit comments

Comments
 (0)