Class: Uffizzi::UI::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/uffizzi/shell.rb

Defined Under Namespace

Classes: ExitError

Constant Summary collapse

PRETTY_JSON =
'pretty-json'
REGULAR_JSON =
'json'
PRETTY_LIST =
'pretty-list'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



16
17
18
# File 'lib/uffizzi/shell.rb', line 16

def initialize
  @shell = Thor::Shell::Basic.new
end

Instance Attribute Details

#output_formatObject

Returns the value of attribute output_format.



10
11
12
# File 'lib/uffizzi/shell.rb', line 10

def output_format
  @output_format
end

Instance Method Details

#ask(message, *args) ⇒ Object



36
37
38
39
40
41
# File 'lib/uffizzi/shell.rb', line 36

def ask(message, *args)
  answer = @shell.ask(message, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  say("\n") unless options.fetch(:echo, true)
  answer
end

#capture3(command) ⇒ Object



67
68
69
# File 'lib/uffizzi/shell.rb', line 67

def capture3(command)
  Open3.capture3(command)
end

#disable_stdoutObject



47
48
49
# File 'lib/uffizzi/shell.rb', line 47

def disable_stdout
  $stdout = StringIO.new
end

#enable_stdoutObject



51
52
53
# File 'lib/uffizzi/shell.rb', line 51

def enable_stdout
  $stdout = IO.new(1, 'w')
end

#last_messageObject



43
44
45
# File 'lib/uffizzi/shell.rb', line 43

def last_message
  @shell.send(:stdout).string.strip
end

#popen(command) ⇒ Object



59
60
61
# File 'lib/uffizzi/shell.rb', line 59

def popen(command)
  IO.popen(command)
end

#popen2e(command, &block) ⇒ Object



63
64
65
# File 'lib/uffizzi/shell.rb', line 63

def popen2e(command, &block)
  Open3.popen2e(command, &block)
end


28
29
30
# File 'lib/uffizzi/shell.rb', line 28

def print_in_columns(messages)
  @shell.print_in_columns(messages)
end


32
33
34
# File 'lib/uffizzi/shell.rb', line 32

def print_table(table_data)
  @shell.print_table(table_data)
end

#say(message) ⇒ Object



20
21
22
# File 'lib/uffizzi/shell.rb', line 20

def say(message)
  @shell.say(format_message(message))
end

#say_error_and_exit(message) ⇒ Object

Raises:



24
25
26
# File 'lib/uffizzi/shell.rb', line 24

def say_error_and_exit(message)
  raise ExitError.new(format_message(message))
end

#stdout_pipe?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/uffizzi/shell.rb', line 55

def stdout_pipe?
  $stdout.stat.pipe?
end