Skip to content

Commit

Permalink
Support topic tags in UI::CLI#debug and #warn
Browse files Browse the repository at this point in the history
If the first argument passed to #debug or #warn is a Symbol, then it
is used to decide whether to print the message or not, basing on
--debug-* CLI options.
  • Loading branch information
skalee committed Mar 17, 2021
1 parent b4ee20e commit f6222f5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/iev/termbase/cli/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ def clear_progress
$TERMBASE_PROGRESS ? "\r#{" " * 40}\r" : ""
end

def cli_out(_level, *args)
def cli_out(level, *args)
topic = Symbol === args[0] ? args.shift : nil
message = args.map(&:to_s).join(" ").chomp
ui_tag = Thread.current[:iev_ui_tag]

return unless should_out?(level, topic)

print [
clear_progress,
ui_tag,
Expand All @@ -57,6 +60,10 @@ def cli_out(_level, *args)
"\n",
].join
end

def should_out?(level, topic)
topic.nil? || level == :warn || $TERMBASE_DEBUG[topic]
end
end
end
end
Expand Down

0 comments on commit f6222f5

Please sign in to comment.