module Spoom::Cli::Helper
Constants
- HIGHLIGHT_COLOR
Color used to highlight expressions in backticks
Public Instance Methods
blue(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 127 def blue(string) colorize(string, :blue) end
color?()
click to toggle source
# File lib/spoom/cli/helper.rb, line 92 def color? options[:color] end
colorize(string, color)
click to toggle source
# File lib/spoom/cli/helper.rb, line 121 def colorize(string, color) return string unless color? string.colorize(color) end
exec_path()
click to toggle source
# File lib/spoom/cli/helper.rb, line 71 def exec_path options[:path] end
gray(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 132 def gray(string) colorize(string, :light_black) end
green(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 137 def green(string) colorize(string, :green) end
highlight(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 97 def highlight(string) return string unless color? res = StringIO.new word = StringIO.new in_ticks = T.let(false, T::Boolean) string.chars.each do |c| if c == '`' && !in_ticks in_ticks = true elsif c == '`' && in_ticks in_ticks = false res << colorize(word.string, HIGHLIGHT_COLOR) word = StringIO.new elsif in_ticks word << c else res << c end end res.string end
in_sorbet_project!()
click to toggle source
# File lib/spoom/cli/helper.rb, line 58 def in_sorbet_project! unless in_sorbet_project? say_error( "not in a Sorbet project (`#{sorbet_config_file}` not found)\n\n" \ "When running spoom from another path than the project's root, " \ "use `--path PATH` to specify the path to the root." ) Kernel.exit(1) end end
in_sorbet_project?()
click to toggle source
# File lib/spoom/cli/helper.rb, line 50 def in_sorbet_project? File.file?(sorbet_config_file) end
red(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 142 def red(string) colorize(string, :red) end
say(message)
click to toggle source
# File lib/spoom/cli/helper.rb, line 19 def say(message) buffer = StringIO.new buffer << highlight(message) buffer << "\n" unless message.end_with?("\n") $stdout.print(buffer.string) $stdout.flush end
say_error(message, status: "Error", nl: true)
click to toggle source
# File lib/spoom/cli/helper.rb, line 38 def say_error(message, status: "Error", nl: true) buffer = StringIO.new buffer << "#{red(status)}: " if status buffer << highlight(message) buffer << "\n" if nl && !message.end_with?("\n") $stderr.print(buffer.string) $stderr.flush end
sorbet_config()
click to toggle source
# File lib/spoom/cli/helper.rb, line 81 def sorbet_config Sorbet::Config.parse_file(sorbet_config_file) end
sorbet_config_file()
click to toggle source
# File lib/spoom/cli/helper.rb, line 76 def sorbet_config_file Pathname.new("#{exec_path}/#{Spoom::Sorbet::CONFIG_PATH}").cleanpath.to_s end
yellow(string)
click to toggle source
# File lib/spoom/cli/helper.rb, line 147 def yellow(string) colorize(string, :yellow) end