Sha256: ea24920b3d9fdd3d7bb7854e9a638be5ef0d8ad1370af47e8f320728f6909d27
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
# typed: strict # frozen_string_literal: true require "pathname" require "stringio" module Spoom module Cli module Helper extend T::Sig include Thor::Shell # Print `message` on `$stderr` # # The message is prefixed by a status (default: `Error`). sig { params(message: String, status: String).void } 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 # Is `spoom` ran inside a project with a `sorbet/config` file? sig { returns(T::Boolean) } def in_sorbet_project? File.file?(sorbet_config) end # Enforce that `spoom` is ran inside a project with a `sorbet/config` file # # Display an error message and exit otherwise. sig { void } def in_sorbet_project! unless in_sorbet_project? say_error("not in a Sorbet project (no sorbet/config)") Kernel.exit(1) end end # Return the path specified through `--path` sig { returns(String) } def exec_path T.unsafe(self).options[:path] # TODO: requires_ancestor end sig { returns(String) } def sorbet_config Pathname.new("#{exec_path}/#{Spoom::Config::SORBET_CONFIG}").cleanpath.to_s end # Is the `--color` option true? sig { returns(T::Boolean) } def color? T.unsafe(self).options[:color] # TODO: requires_ancestor end # Colorize a string if `color?` sig { params(string: String, color: Symbol).returns(String) } def colorize(string, color) return string unless color? string.colorize(color) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spoom-1.0.6 | lib/spoom/cli/helper.rb |
spoom-1.0.5 | lib/spoom/cli/helper.rb |