Class: Bundler::UI::Shell
- Inherits:
-
Object
- Object
- Bundler::UI::Shell
- Defined in:
- lib/bundler/ui/shell.rb
Constant Summary collapse
- LEVELS =
%w[silent error warn confirm info debug].freeze
- OUTPUT_STREAMS =
[:stdout, :stderr].freeze
Instance Attribute Summary collapse
-
#output_stream ⇒ Object
Returns the value of attribute output_stream.
-
#shell ⇒ Object
writeonly
Sets the attribute shell.
Instance Method Summary collapse
- #add_color(string, *color) ⇒ Object
- #ask(msg) ⇒ Object
- #confirm(msg = nil, newline = nil) ⇒ Object
- #confirm? ⇒ Boolean
- #debug(msg = nil, newline = nil) ⇒ Object
- #debug? ⇒ Boolean
- #error(msg = nil, newline = nil, color = :red) ⇒ Object
- #error? ⇒ Boolean
- #info(msg = nil, newline = nil) ⇒ Object
- #info? ⇒ Boolean
-
#initialize(options = {}) ⇒ Shell
constructor
A new instance of Shell.
- #level(name = nil) ⇒ Object
- #level=(level) ⇒ Object
- #no?(msg) ⇒ Boolean
- #progress(&blk) ⇒ Object
- #quiet? ⇒ Boolean
- #silence(&blk) ⇒ Object
- #trace(e, newline = nil, force = false) ⇒ Object
- #unprinted_warnings ⇒ Object
- #warn(msg = nil, newline = nil, color = :yellow) ⇒ Object
- #warn? ⇒ Boolean
- #yes?(msg) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Shell
Returns a new instance of Shell.
14 15 16 17 18 19 20 |
# File 'lib/bundler/ui/shell.rb', line 14 def initialize( = {}) Thor::Base.shell = ["no-color"] ? Thor::Shell::Basic : nil @shell = Thor::Base.shell.new @level = ENV["DEBUG"] ? "debug" : "info" @warning_history = [] @output_stream = :stdout end |
Instance Attribute Details
#output_stream ⇒ Object
Returns the value of attribute output_stream.
12 13 14 |
# File 'lib/bundler/ui/shell.rb', line 12 def output_stream @output_stream end |
#shell=(value) ⇒ Object (writeonly)
Sets the attribute shell
11 12 13 |
# File 'lib/bundler/ui/shell.rb', line 11 def shell=(value) @shell = value end |
Instance Method Details
#add_color(string, *color) ⇒ Object
22 23 24 |
# File 'lib/bundler/ui/shell.rb', line 22 def add_color(string, *color) @shell.set_color(string, *color) end |
#ask(msg) ⇒ Object
82 83 84 |
# File 'lib/bundler/ui/shell.rb', line 82 def ask(msg) @shell.ask(msg) end |
#confirm(msg = nil, newline = nil) ⇒ Object
32 33 34 35 36 |
# File 'lib/bundler/ui/shell.rb', line 32 def confirm(msg = nil, newline = nil) return unless confirm? tell_me(msg || yield, :green, newline) end |
#confirm? ⇒ Boolean
62 63 64 |
# File 'lib/bundler/ui/shell.rb', line 62 def confirm? level("confirm") end |
#debug(msg = nil, newline = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/bundler/ui/shell.rb', line 52 def debug(msg = nil, newline = nil) return unless debug? tell_me(msg || yield, nil, newline) end |
#debug? ⇒ Boolean
74 75 76 |
# File 'lib/bundler/ui/shell.rb', line 74 def debug? level("debug") end |
#error(msg = nil, newline = nil, color = :red) ⇒ Object
46 47 48 49 50 |
# File 'lib/bundler/ui/shell.rb', line 46 def error(msg = nil, newline = nil, color = :red) return unless error? tell_err(msg || yield, color, newline) end |
#error? ⇒ Boolean
70 71 72 |
# File 'lib/bundler/ui/shell.rb', line 70 def error? level("error") end |
#info(msg = nil, newline = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/bundler/ui/shell.rb', line 26 def info(msg = nil, newline = nil) return unless info? tell_me(msg || yield, nil, newline) end |
#info? ⇒ Boolean
58 59 60 |
# File 'lib/bundler/ui/shell.rb', line 58 def info? level("info") end |
#level(name = nil) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/bundler/ui/shell.rb', line 99 def level(name = nil) return @level unless name unless index = LEVELS.index(name) raise "#{name.inspect} is not a valid level" end index <= LEVELS.index(@level) end |
#level=(level) ⇒ Object
94 95 96 97 |
# File 'lib/bundler/ui/shell.rb', line 94 def level=(level) raise ArgumentError unless LEVELS.include?(level.to_s) @level = level.to_s end |
#no?(msg) ⇒ Boolean
90 91 92 |
# File 'lib/bundler/ui/shell.rb', line 90 def no?(msg) @shell.no?(msg) end |
#progress(&blk) ⇒ Object
122 123 124 |
# File 'lib/bundler/ui/shell.rb', line 122 def progress(&blk) with_output_stream(:stderr, &blk) end |
#quiet? ⇒ Boolean
78 79 80 |
# File 'lib/bundler/ui/shell.rb', line 78 def quiet? level("quiet") end |
#silence(&blk) ⇒ Object
118 119 120 |
# File 'lib/bundler/ui/shell.rb', line 118 def silence(&blk) with_level("silent", &blk) end |
#trace(e, newline = nil, force = false) ⇒ Object
112 113 114 115 116 |
# File 'lib/bundler/ui/shell.rb', line 112 def trace(e, newline = nil, force = false) return unless debug? || force msg = "#{e.class}: #{e.}\n#{e.backtrace.join("\n ")}" tell_err(msg, nil, newline) end |
#unprinted_warnings ⇒ Object
126 127 128 |
# File 'lib/bundler/ui/shell.rb', line 126 def unprinted_warnings [] end |
#warn(msg = nil, newline = nil, color = :yellow) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/bundler/ui/shell.rb', line 38 def warn(msg = nil, newline = nil, color = :yellow) return unless warn? return if @warning_history.include? msg @warning_history << msg tell_err(msg || yield, color, newline) end |
#warn? ⇒ Boolean
66 67 68 |
# File 'lib/bundler/ui/shell.rb', line 66 def warn? level("warn") end |
#yes?(msg) ⇒ Boolean
86 87 88 |
# File 'lib/bundler/ui/shell.rb', line 86 def yes?(msg) @shell.yes?(msg) end |