Module: Spoom::Cli::Helper
- Extended by:
- T::Sig
- Includes:
- Thor::Shell
- Defined in:
- lib/spoom/cli/helper.rb
Instance Method Summary collapse
- #color? ⇒ Boolean
- #colorize(string, color) ⇒ Object
- #exec_path ⇒ Object
- #in_sorbet_project! ⇒ Object
- #in_sorbet_project? ⇒ Boolean
- #say_error(message, status = "Error") ⇒ Object
- #sorbet_config ⇒ Object
Instance Method Details
#color? ⇒ Boolean
62 63 64 |
# File 'lib/spoom/cli/helper.rb', line 62 def color? T.unsafe(self).[:color] # TODO: requires_ancestor end |
#colorize(string, color) ⇒ Object
68 69 70 71 |
# File 'lib/spoom/cli/helper.rb', line 68 def colorize(string, color) return string unless color? string.colorize(color) end |
#exec_path ⇒ Object
51 52 53 |
# File 'lib/spoom/cli/helper.rb', line 51 def exec_path T.unsafe(self).[:path] # TODO: requires_ancestor end |
#in_sorbet_project! ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spoom/cli/helper.rb', line 38 def in_sorbet_project! unless in_sorbet_project? say_error( "not in a Sorbet project (#{colorize(sorbet_config, :yellow)} not found)\n\n" \ "When running spoom from another path than the project's root, " \ "use #{colorize('--path PATH', :blue)} to specify the path to the root." ) Kernel.exit(1) end end |
#in_sorbet_project? ⇒ Boolean
30 31 32 |
# File 'lib/spoom/cli/helper.rb', line 30 def in_sorbet_project? File.file?(sorbet_config) end |
#say_error(message, status = "Error") ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/spoom/cli/helper.rb', line 17 def say_error(, status = "Error") status = set_color(status, :red) buffer = StringIO.new buffer << "#{status}: #{}" buffer << "\n" unless .end_with?("\n") $stderr.print(buffer.string) $stderr.flush end |
#sorbet_config ⇒ Object
56 57 58 |
# File 'lib/spoom/cli/helper.rb', line 56 def sorbet_config Pathname.new("#{exec_path}/#{Spoom::Config::SORBET_CONFIG}").cleanpath.to_s end |