Skip to content

Commit f6e9562

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 f6e9562

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Summary
2+
3+
Add a new `--formats` CLI flag wired directly to `Skunk::Config.formats` during option parsing, plus documentation updates to show how to use it.
4+
5+
## Implementation
6+
7+
1. CLI option parsing
8+
9+
- File: lib/skunk/cli/options/argv.rb
10+
- Add `require "skunk/config"` at the top so the parser can set formats.
11+
- In `parse`, add: `opts.on("--formats x,y,z", Array, "Output formats: json,html,console") { |list| Skunk::Config.formats = list.map(&:to_sym) }`
12+
- Do not add any new accessors and do not modify `to_h`.
13+
14+
2. Tests
15+
16+
- File: test/lib/skunk/cli/options/argv_test.rb
17+
- Add a test that passes `--formats=json,html`, invokes `parse`, asserts `Skunk::Config.formats == %i[json html]`, and resets with `Skunk::Config.reset`.
18+
19+
3. Documentation
20+
21+
- File: README.md
22+
- Add a short “CLI formats” subsection showing:
23+
- `skunk --formats=json`
24+
- `skunk --formats=json,html`
25+
- Mention accepted values: `json`, `html`, `console` and that default is `console` when omitted.
26+
- Keep existing programmatic examples, but clarify they are equivalent to the CLI flag.
27+
28+
## Validation
29+
30+
- Run tests to ensure the flag is parsed and configuration is applied.
31+
- Optional manual steps: run `skunk --formats=json` and `skunk --formats=json,html` and observe the generated reports.
32+
33+
## Notes
34+
35+
- No changes to `Application` or option hashes; minimal surface change following your preference.

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

0 commit comments

Comments
 (0)