Class: Shell
- Inherits:
-
Object
- Object
- Shell
- Defined in:
- lib/core/shell.rb
Class Attribute Summary collapse
-
.tmp_stderr ⇒ Object
readonly
Returns the value of attribute tmp_stderr.
-
.verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Class Method Summary collapse
- .abort(message) ⇒ Object
- .color(message, color_key) ⇒ Object
- .confirm(message) ⇒ Object
- .debug(prefix, message, sensitive_data_pattern: nil) ⇒ Object
-
.hide_sensitive_data(message, pattern = nil) ⇒ String
Hide sensitive data based on the passed pattern.
- .read_from_tmp_stderr ⇒ Object
- .shell ⇒ Object
- .should_hide_output? ⇒ Boolean
- .stderr ⇒ Object
- .use_tmp_stderr ⇒ Object
- .verbose_mode(verbose) ⇒ Object
- .warn(message) ⇒ Object
- .warn_deprecated(message) ⇒ Object
- .write_to_tmp_stderr(message) ⇒ Object
Class Attribute Details
.tmp_stderr ⇒ Object (readonly)
Returns the value of attribute tmp_stderr.
5 6 7 |
# File 'lib/core/shell.rb', line 5 def tmp_stderr @tmp_stderr end |
.verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
5 6 7 |
# File 'lib/core/shell.rb', line 5 def verbose @verbose end |
Class Method Details
.abort(message) ⇒ Object
50 51 52 |
# File 'lib/core/shell.rb', line 50 def self.abort() Kernel.abort(color("ERROR: #{}", :red)) end |
.color(message, color_key) ⇒ Object
34 35 36 |
# File 'lib/core/shell.rb', line 34 def self.color(, color_key) shell.set_color(, color_key) end |
.confirm(message) ⇒ Object
38 39 40 |
# File 'lib/core/shell.rb', line 38 def self.confirm() shell.yes?("#{} (y/N)") end |
.debug(prefix, message, sensitive_data_pattern: nil) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/core/shell.rb', line 58 def self.debug(prefix, , sensitive_data_pattern: nil) return unless verbose = hide_sensitive_data(, sensitive_data_pattern) stderr.puts("\n[#{color(prefix, :red)}] #{}") end |
.hide_sensitive_data(message, pattern = nil) ⇒ String
Hide sensitive data based on the passed pattern
82 83 84 85 86 |
# File 'lib/core/shell.rb', line 82 def self.hide_sensitive_data(, pattern = nil) return unless pattern.is_a?(Regexp) .gsub(pattern, "XXXXXXX") end |
.read_from_tmp_stderr ⇒ Object
29 30 31 32 |
# File 'lib/core/shell.rb', line 29 def self.read_from_tmp_stderr tmp_stderr.rewind tmp_stderr.read.strip end |
.shell ⇒ Object
8 9 10 |
# File 'lib/core/shell.rb', line 8 def self.shell @shell ||= Thor::Shell::Color.new end |
.should_hide_output? ⇒ Boolean
65 66 67 |
# File 'lib/core/shell.rb', line 65 def self.should_hide_output? tmp_stderr && !verbose end |
.stderr ⇒ Object
12 13 14 |
# File 'lib/core/shell.rb', line 12 def self.stderr @stderr ||= $stderr end |
.use_tmp_stderr ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/core/shell.rb', line 16 def self.use_tmp_stderr @tmp_stderr = Tempfile.create yield @tmp_stderr.close @tmp_stderr = nil end |
.verbose_mode(verbose) ⇒ Object
54 55 56 |
# File 'lib/core/shell.rb', line 54 def self.verbose_mode(verbose) @verbose = verbose end |
.warn(message) ⇒ Object
42 43 44 |
# File 'lib/core/shell.rb', line 42 def self.warn() stderr.puts(color("WARNING: #{}", :yellow)) end |
.warn_deprecated(message) ⇒ Object
46 47 48 |
# File 'lib/core/shell.rb', line 46 def self.warn_deprecated() stderr.puts(color("DEPRECATED: #{}", :yellow)) end |
.write_to_tmp_stderr(message) ⇒ Object
25 26 27 |
# File 'lib/core/shell.rb', line 25 def self.write_to_tmp_stderr() tmp_stderr.write() end |