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 08f156e commit 560484d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions 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", "-V", "--help", "-h"].include?(flag)
["--generate-todo", "--fix", "--no-fix", "--version", "-v", "--verbose-version", "-V", "--help", "-h"].include?(flag)
end
end

Expand All @@ -39,7 +39,7 @@ def determine_command(argv)
:help
elsif (argv & ["--version", "-v"]).any?
:version
elsif (argv & ["-V"]).any?
elsif (argv & ["--verbose-version", "-V"]).any?
:verbose_version
elsif (argv & ["--generate-todo"]).any?
:genignore
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
15 changes: 3 additions & 12 deletions lib/standard/runners/verbose_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ module Standard
module Runners
class VerboseVersion
def call(config)
rubocop_runner = RuboCop::CLI::Command::ExecuteRunner.new(
RuboCop::CLI::Environment.new(
RuboCop::Options.new.parse(["-V"]),
{},
{}
)
)

rubocop_runner.run
puts <<-MESSAGE.gsub(/^ {10}/, "")
RuboCop version: #{rubocop_verbose_version}
puts <<-MSG.gsub(/^ {10}/, "")
Standard version: #{Standard::VERSION}
MESSAGE
RuboCop version: #{RuboCop::Version.version(debug: true)}
MSG
end
end
end
Expand Down
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
13 changes: 11 additions & 2 deletions test/standard/runners/verbose_version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ def test_verbose_version
fake_out, _ = do_with_fake_io {
@subject.call(nil)
}

expect = <<-EXPECT.gsub(/^ {6}/, "")
RuboCop version: #{RuboCop::Version.version}
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 560484d

Please sign in to comment.