diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fe3af97..2a6a96c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2025-10-17 22:53:06 UTC using RuboCop version 1.81.1. +# on 2025-11-14 17:50:37 UTC using RuboCop version 1.81.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -24,21 +24,21 @@ Lint/MissingSuper: - 'lib/skunk/cli/application.rb' - 'lib/skunk/generators/html/overview.rb' -# Offense count: 4 +# Offense count: 5 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 24 -# Offense count: 14 +# Offense count: 13 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: Max: 208 -# Offense count: 5 +# Offense count: 7 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 18 + Max: 20 # Offense count: 1 # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. @@ -66,10 +66,3 @@ Style/FrozenStringLiteralComment: Exclude: - '**/*.arb' - 'bin/console' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings. -# URISchemes: http, https -Layout/LineLength: - Max: 124 diff --git a/CHANGELOG.md b/CHANGELOG.md index 112ad26..3c15596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD) +* BUGFIX: Pin path_expander < 2.0 for Ruby 2.7 compatibility +* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)](https://github.com/fastruby/skunk/pull/130) * [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128) * [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129) * [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127) diff --git a/README.md b/README.md index c3659a3..1792f04 100644 --- a/README.md +++ b/README.md @@ -158,16 +158,33 @@ This should give you an idea if you're moving in the direction of maintaining th ### Setting Output Formats -Skunk provides a simple configuration class to control output formats programmatically. You can use `Skunk::Config` to set which formats should be generated when running Skunk. +Skunk supports multiple output formats and you can select them via CLI or programmatically. **Supported formats:** -- `:json` - JSON report (default) +- `:json` - JSON report - `:html` - HTML report with visual charts and tables +- `:console` - Console output (default) + +#### CLI flag + +You can choose one or more formats from the command line: + +``` +skunk --formats=json +skunk --f json,html +skunk --formats console,json +``` + +If omitted, Skunk defaults to `console`. + +#### Programmatic configuration + +You can also configure formats in code using `Skunk::Config`: ```ruby require 'skunk/config' -# Set multiple formats +# Set multiple formats (equivalent to `--formats=json,html`) Skunk::Config.formats = [:json, :html] # Add a format to the existing list @@ -177,7 +194,7 @@ Skunk::Config.add_format(:html) Skunk::Config.remove_format(:json) # Check supported formats -Skunk::Config.supported_formats # => [:json, :html] +Skunk::Config.supported_formats # => [:json, :html, :console] Skunk::Config.supported_format?(:json) # => true # Reset to defaults diff --git a/lib/skunk/cli/application.rb b/lib/skunk/cli/application.rb index f928098..d7c00b4 100644 --- a/lib/skunk/cli/application.rb +++ b/lib/skunk/cli/application.rb @@ -25,6 +25,7 @@ def initialize(argv) def execute warn_coverage_info unless File.exist?(COVERAGE_FILE) + Skunk::Config.reset # :reek:NilCheck @parsed_options = @options.parse.to_h command = Skunk::CommandFactory.create(@parsed_options) diff --git a/lib/skunk/cli/options/argv.rb b/lib/skunk/cli/options/argv.rb index af2bec9..26825cd 100644 --- a/lib/skunk/cli/options/argv.rb +++ b/lib/skunk/cli/options/argv.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "rubycritic/cli/options/argv" +require "skunk/config" module Skunk module Cli @@ -15,29 +16,52 @@ class Argv < RubyCritic::Cli::Options::Argv def parse parser.new do |opts| opts.banner = "Usage: skunk [options] [paths]\n" + add_branch_option(opts) + add_output_option(opts) + add_formats_option(opts) + add_tail_options(opts) + end.parse!(@argv) + end + + def to_h + super.merge(output_filename: output_filename) + end - opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch| - self.base_branch = String(branch) - set_current_branch - self.mode = :compare_branches - end + private - opts.on("-o", "--out FILE", "Output report to file") do |filename| - self.output_filename = filename - end + def add_branch_option(opts) + opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch| + self.base_branch = String(branch) + set_current_branch + self.mode = :compare_branches + end + end - opts.on_tail("-v", "--version", "Show gem's version") do - self.mode = :version - end + def add_output_option(opts) + opts.on("-o", "--out FILE", "Output report to file") do |filename| + self.output_filename = filename + end + end - opts.on_tail("-h", "--help", "Show this message") do - self.mode = :help - end - end.parse!(@argv) + def add_formats_option(opts) + opts.on( + "-f", + "--formats json,html,console", + Array, + "Output formats: json,html,console (default: console)" + ) do |list| + Skunk::Config.formats = Array(list).map(&:to_sym) + end end - def to_h - super.merge(output_filename: output_filename) + def add_tail_options(opts) + opts.on_tail("-v", "--version", "Show gem's version") do + self.mode = :version + end + + opts.on_tail("-h", "--help", "Show this message") do + self.mode = :help + end end end end diff --git a/skunk.gemspec b/skunk.gemspec index f68c820..0252525 100644 --- a/skunk.gemspec +++ b/skunk.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] + spec.add_dependency "path_expander", "< 2.0" spec.add_dependency "rubycritic", ">= 4.5.2", "< 5.0" spec.add_dependency "terminal-table", "~> 3.0" diff --git a/test/lib/skunk/cli/options/argv_test.rb b/test/lib/skunk/cli/options/argv_test.rb index deee125..20bfb45 100644 --- a/test/lib/skunk/cli/options/argv_test.rb +++ b/test/lib/skunk/cli/options/argv_test.rb @@ -24,4 +24,28 @@ end end end + + describe "#formats" do + after do + Skunk::Config.reset + end + + context "passing --formats option" do + let(:argv) { ["--formats=json,html"] } + + it "applies formats to Skunk::Config" do + parser = Skunk::Cli::Options::Argv.new(argv) + parser.parse + _(Skunk::Config.formats).must_equal %i[json html] + end + end + + context "not passing --formats option" do + it "defaults to console format" do + parser = Skunk::Cli::Options::Argv.new([]) + parser.parse + _(Skunk::Config.formats).must_equal [:console] + end + end + end end diff --git a/test/lib/skunk/commands/help_test.rb b/test/lib/skunk/commands/help_test.rb index 994118c..4f25c0d 100644 --- a/test/lib/skunk/commands/help_test.rb +++ b/test/lib/skunk/commands/help_test.rb @@ -12,6 +12,7 @@ Usage: skunk [options] [paths] -b, --branch BRANCH Set branch to compare -o, --out FILE Output report to file + -f, --formats json,html,console Output formats: json,html,console (default: console) -v, --version Show gem's version -h, --help Show this message HELP