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..f9217bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 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) +* [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/options/argv.rb b/lib/skunk/cli/options/argv.rb index af2bec9..4141947 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 @@ -26,6 +27,10 @@ def parse self.output_filename = filename end + opts.on("-f", "--formats json,html,console", Array, "Output formats: json,html,console") do |list| + Skunk::Config.formats = Array(list).map(&:to_sym) + end + opts.on_tail("-v", "--version", "Show gem's version") do self.mode = :version end diff --git a/test/lib/skunk/cli/options/argv_test.rb b/test/lib/skunk/cli/options/argv_test.rb index deee125..bffe1bd 100644 --- a/test/lib/skunk/cli/options/argv_test.rb +++ b/test/lib/skunk/cli/options/argv_test.rb @@ -24,4 +24,19 @@ 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 + end end diff --git a/test/lib/skunk/commands/help_test.rb b/test/lib/skunk/commands/help_test.rb index 994118c..9374e0f 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 -v, --version Show gem's version -h, --help Show this message HELP