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
|
||||
extend self
|
||||
|
||||
private ENABLED_MARK = "✓".colorize(:green)
|
||||
private DISABLED_MARK = "x".colorize(:red)
|
||||
|
||||
def run(args = ARGV)
|
||||
opts = parse_args args
|
||||
location_to_explain = opts.location_to_explain
|
||||
|
@ -184,13 +187,34 @@ module Ameba::Cli
|
|||
end
|
||||
|
||||
private def print_rules(config)
|
||||
config.rules.each do |rule|
|
||||
puts "%s [%s] - %s" % {
|
||||
rule.name.colorize(:white),
|
||||
rules = config.rules.to_h do |rule|
|
||||
name = rule.name.split('/')
|
||||
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),
|
||||
name.ljust(longest_name),
|
||||
rule.description.colorize(:dark_gray),
|
||||
}
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue