Class: Bundler::UI::Shell

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  Thor::Base.shell = options["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_streamObject

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

Parameters:

  • value

    the value to set the attribute shell to.



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Raises:

  • (ArgumentError)


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

Returns:

  • (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

Returns:

  • (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.message}\n#{e.backtrace.join("\n  ")}"
  tell_err(msg, nil, newline)
end

#unprinted_warningsObject



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

Returns:

  • (Boolean)


66
67
68
# File 'lib/bundler/ui/shell.rb', line 66

def warn?
  level("warn")
end

#yes?(msg) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/bundler/ui/shell.rb', line 86

def yes?(msg)
  @shell.yes?(msg)
end