Module: Spoom::Cli::Helper

Extended by:
T::Sig
Includes:
Thor::Shell
Included in:
Bump, Config, Coverage, LSP, Main, Run
Defined in:
lib/spoom/cli/helper.rb

Instance Method Summary collapse

Instance Method Details

#color?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/spoom/cli/helper.rb', line 62

def color?
  T.unsafe(self).options[: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_pathObject



51
52
53
# File 'lib/spoom/cli/helper.rb', line 51

def exec_path
  T.unsafe(self).options[: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

Returns:

  • (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(message, status = "Error")
  status = set_color(status, :red)

  buffer = StringIO.new
  buffer << "#{status}: #{message}"
  buffer << "\n" unless message.end_with?("\n")

  $stderr.print(buffer.string)
  $stderr.flush
end

#sorbet_configObject



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