Skip to content

Commit 51ce9d3

Browse files
committed
feat(cli): add --formats flag to support multiple output formats
Add support for selecting output formats via CLI with the new --formats flag. Update documentation to explain usage and maintain existing programmatic config.
1 parent ff8b0f8 commit 51ce9d3

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.4...HEAD)
99

10+
* [FEATURE: Add `--formats` CLI flag to select report formats (json, html, console)]
1011
* [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128)
1112
* [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129)
1213
* [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127)

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,33 @@ This should give you an idea if you're moving in the direction of maintaining th
158158

159159
### Setting Output Formats
160160

161-
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.
161+
Skunk supports multiple output formats and you can select them via CLI or programmatically.
162162

163163
**Supported formats:**
164-
- `:json` - JSON report (default)
164+
- `:json` - JSON report
165165
- `:html` - HTML report with visual charts and tables
166+
- `:console` - Console output (default)
167+
168+
#### CLI flag
169+
170+
You can choose one or more formats from the command line:
171+
172+
```
173+
skunk --formats=json
174+
skunk --f json,html
175+
skunk --formats console,json
176+
```
177+
178+
If omitted, Skunk defaults to `console`.
179+
180+
#### Programmatic configuration
181+
182+
You can also configure formats in code using `Skunk::Config`:
166183

167184
```ruby
168185
require 'skunk/config'
169186

170-
# Set multiple formats
187+
# Set multiple formats (equivalent to `--formats=json,html`)
171188
Skunk::Config.formats = [:json, :html]
172189

173190
# Add a format to the existing list
@@ -177,7 +194,7 @@ Skunk::Config.add_format(:html)
177194
Skunk::Config.remove_format(:json)
178195

179196
# Check supported formats
180-
Skunk::Config.supported_formats # => [:json, :html]
197+
Skunk::Config.supported_formats # => [:json, :html, :console]
181198
Skunk::Config.supported_format?(:json) # => true
182199

183200
# Reset to defaults

lib/skunk/cli/options/argv.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "rubycritic/cli/options/argv"
4+
require "skunk/config"
45

56
module Skunk
67
module Cli
@@ -26,6 +27,10 @@ def parse
2627
self.output_filename = filename
2728
end
2829

30+
opts.on("-f", "--formats x,y,z", Array, "Output formats: json,html,console") do |list|
31+
Skunk::Config.formats = Array(list).map(&:to_sym)
32+
end
33+
2934
opts.on_tail("-v", "--version", "Show gem's version") do
3035
self.mode = :version
3136
end

test/lib/skunk/cli/options/argv_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,20 @@
2424
end
2525
end
2626
end
27+
28+
describe "#formats" do
29+
context "passing --formats option" do
30+
let(:argv) { ["--formats=json,html"] }
31+
32+
it "applies formats to Skunk::Config" do
33+
begin
34+
parser = Skunk::Cli::Options::Argv.new(argv)
35+
parser.parse
36+
_(Skunk::Config.formats).must_equal %i[json html]
37+
ensure
38+
Skunk::Config.reset
39+
end
40+
end
41+
end
42+
end
2743
end

test/lib/skunk/commands/help_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Usage: skunk [options] [paths]
1313
-b, --branch BRANCH Set branch to compare
1414
-o, --out FILE Output report to file
15+
-f, --formats x,y,z Output formats: json,html,console
1516
-v, --version Show gem's version
1617
-h, --help Show this message
1718
HELP

0 commit comments

Comments
 (0)