Skip to content

Commit 3e5a697

Browse files
committed
fix(cli): wrap formats option
1 parent 633f011 commit 3e5a697

1 file changed

Lines changed: 39 additions & 20 deletions

File tree

lib/skunk/cli/options/argv.rb

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,52 @@ class Argv < RubyCritic::Cli::Options::Argv
1616
def parse
1717
parser.new do |opts|
1818
opts.banner = "Usage: skunk [options] [paths]\n"
19+
add_branch_option(opts)
20+
add_output_option(opts)
21+
add_formats_option(opts)
22+
add_tail_options(opts)
23+
end.parse!(@argv)
24+
end
1925

20-
opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch|
21-
self.base_branch = String(branch)
22-
set_current_branch
23-
self.mode = :compare_branches
24-
end
26+
def to_h
27+
super.merge(output_filename: output_filename)
28+
end
2529

26-
opts.on("-o", "--out FILE", "Output report to file") do |filename|
27-
self.output_filename = filename
28-
end
30+
private
2931

30-
opts.on("-f", "--formats json,html,console", Array, "Output formats: json,html,console (default: console)") do |list|
31-
Skunk::Config.formats = Array(list).map(&:to_sym)
32-
end
32+
def add_branch_option(opts)
33+
opts.on("-b", "--branch BRANCH", "Set branch to compare") do |branch|
34+
self.base_branch = String(branch)
35+
set_current_branch
36+
self.mode = :compare_branches
37+
end
38+
end
3339

34-
opts.on_tail("-v", "--version", "Show gem's version") do
35-
self.mode = :version
36-
end
40+
def add_output_option(opts)
41+
opts.on("-o", "--out FILE", "Output report to file") do |filename|
42+
self.output_filename = filename
43+
end
44+
end
3745

38-
opts.on_tail("-h", "--help", "Show this message") do
39-
self.mode = :help
40-
end
41-
end.parse!(@argv)
46+
def add_formats_option(opts)
47+
opts.on(
48+
"-f",
49+
"--formats json,html,console",
50+
Array,
51+
"Output formats: json,html,console (default: console)"
52+
) do |list|
53+
Skunk::Config.formats = Array(list).map(&:to_sym)
54+
end
4255
end
4356

44-
def to_h
45-
super.merge(output_filename: output_filename)
57+
def add_tail_options(opts)
58+
opts.on_tail("-v", "--version", "Show gem's version") do
59+
self.mode = :version
60+
end
61+
62+
opts.on_tail("-h", "--help", "Show this message") do
63+
self.mode = :help
64+
end
4665
end
4766
end
4867
end

0 commit comments

Comments
 (0)