mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Refactor --rules
CLI switch output
This commit is contained in:
parent
1718945523
commit
f1f21ac94d
1 changed files with 29 additions and 5 deletions
|
@ -5,6 +5,9 @@ require "option_parser"
|
||||||
module Ameba::Cli
|
module Ameba::Cli
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
|
private ENABLED_MARK = "✓".colorize(:green)
|
||||||
|
private DISABLED_MARK = "x".colorize(:red)
|
||||||
|
|
||||||
def run(args = ARGV)
|
def run(args = ARGV)
|
||||||
opts = parse_args args
|
opts = parse_args args
|
||||||
location_to_explain = opts.location_to_explain
|
location_to_explain = opts.location_to_explain
|
||||||
|
@ -184,13 +187,34 @@ module Ameba::Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
private def print_rules(config)
|
private def print_rules(config)
|
||||||
config.rules.each do |rule|
|
rules = config.rules.to_h do |rule|
|
||||||
puts "%s [%s] - %s" % {
|
name = rule.name.split('/')
|
||||||
rule.name.colorize(:white),
|
name = "%s/%s" % {
|
||||||
|
name[0...-1].join('/').colorize(:light_gray),
|
||||||
|
name.last.colorize(:white),
|
||||||
|
}
|
||||||
|
{name, rule}
|
||||||
|
end
|
||||||
|
longest_name = rules.max_of(&.first.size)
|
||||||
|
|
||||||
|
rules.group_by(&.last.group).each do |group, group_rules|
|
||||||
|
puts "— %s" % group.colorize(:light_blue).underline
|
||||||
|
puts
|
||||||
|
group_rules.each do |name, rule|
|
||||||
|
puts " %s [%s] %s %s" % {
|
||||||
|
rule.enabled? ? ENABLED_MARK : DISABLED_MARK,
|
||||||
rule.severity.symbol.to_s.colorize(:green),
|
rule.severity.symbol.to_s.colorize(:green),
|
||||||
|
name.ljust(longest_name),
|
||||||
rule.description.colorize(:dark_gray),
|
rule.description.colorize(:dark_gray),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Total rules: %s / %s enabled" % {
|
||||||
|
rules.size.to_s.colorize(:light_blue),
|
||||||
|
rules.count(&.last.enabled?).to_s.colorize(:light_blue),
|
||||||
|
}
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue