Skip to content

Commit 48ffe6c

Browse files
committed
feat(cli): support multiple output formats via --out
Parse comma-separated formats in --out and set Skunk::Config.formats.\n\nBreaking change: replaces previous --out=FILE behavior.\nDocs: updated help text and examples in README; added CHANGELOG entry.
1 parent ff8b0f8 commit 48ffe6c

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ 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: `--out` now accepts multiple formats and sets `Skunk::Config.formats`](#)
11+
* [BREAKING: Replace `--out=FILE` file output with formats configuration (`--out=json,html`) ](#)
12+
1013
* [REFACTOR: Move Console Report](https://github.com/fastruby/skunk/pull/128)
1114
* [BUGFIX: Set the right content type in the share HTTP request](https://github.com/fastruby/skunk/pull/129)
1215
* [REFACTOR: Centralize Skunk analysis into RubyCritic module](https://github.com/fastruby/skunk/pull/127)

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Run `skunk -h` to check out the help options:
6565
```
6666
Usage: skunk [options] [paths]
6767
-b, --branch BRANCH Set branch to compare
68-
-o, --out FILE Output report to file
68+
-o, --out console,json,html Output formats
6969
-v, --version Show gem's version
7070
-h, --help Show this message
7171
```
@@ -161,8 +161,9 @@ This should give you an idea if you're moving in the direction of maintaining th
161161
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.
162162

163163
**Supported formats:**
164-
- `:json` - JSON report (default)
165-
- `:html` - HTML report with visual charts and tables
164+
- `:console` - Console report (default)
165+
- `:json` - JSON report
166+
- `:html` - HTML report with visual charts and tables
166167

167168
```ruby
168169
require 'skunk/config'
@@ -184,6 +185,13 @@ Skunk::Config.supported_format?(:json) # => true
184185
Skunk::Config.reset
185186
```
186187

188+
You can also configure formats via the CLI using `--out` with a comma-separated list:
189+
190+
```
191+
skunk --out=json,html
192+
skunk -o console
193+
```
194+
187195
## Sharing your SkunkScore
188196

189197
If you want to share the results of your Skunk report with the Ruby community, run:

lib/skunk/cli/options/argv.rb

Lines changed: 3 additions & 2 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
@@ -22,8 +23,8 @@ def parse
2223
self.mode = :compare_branches
2324
end
2425

25-
opts.on("-o", "--out FILE", "Output report to file") do |filename|
26-
self.output_filename = filename
26+
opts.on("-o", "--out console,json,html", Array, "Output formats") do |formats|
27+
Skunk::Config.formats = formats.map(&:to_sym)
2728
end
2829

2930
opts.on_tail("-v", "--version", "Show gem's version") do

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
require "test_helper"
44

55
require "skunk/cli/options/argv"
6+
require "skunk/config"
67

78
describe Skunk::Cli::Options::Argv do
8-
describe "#output_filename" do
9-
context "passing --out=FILE options" do
10-
let(:argv) { ["--out=file.txt"] }
9+
describe "--out formats" do
10+
context "passing --out=json,html" do
11+
let(:argv) { ["--out=json,html"] }
1112

12-
it "parses passed filename" do
13+
it "sets Config.formats accordingly" do
14+
Skunk::Config.reset
1315
parser = Skunk::Cli::Options::Argv.new(argv)
1416
parser.parse
15-
_(parser.output_filename).must_equal "file.txt"
17+
_(Skunk::Config.formats).must_equal %i[json html]
1618
end
1719
end
1820

1921
context "not passing the --out option" do
20-
it "is nil" do
22+
it "keeps default formats" do
23+
Skunk::Config.reset
2124
parser = Skunk::Cli::Options::Argv.new([])
2225
parser.parse
23-
_(parser.output_filename).must_be_nil
26+
_(Skunk::Config.formats).must_equal [:console]
2427
end
2528
end
2629
end

0 commit comments

Comments
 (0)