Class: Uffizzi::UI::Shell
- Inherits:
-
Object
- Object
- Uffizzi::UI::Shell
- 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
-
#output_format ⇒ Object
Returns the value of attribute output_format.
Instance Method Summary collapse
- #ask(message, *args) ⇒ Object
- #capture3(command) ⇒ Object
- #disable_stdout ⇒ Object
- #enable_stdout ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #last_message ⇒ Object
- #popen(command) ⇒ Object
- #popen2e(command, &block) ⇒ Object
- #print_in_columns(messages) ⇒ Object
- #print_table(table_data) ⇒ Object
- #say(message) ⇒ Object
- #say_error_and_exit(message) ⇒ Object
- #stdout_pipe? ⇒ Boolean
Constructor Details
#initialize ⇒ Shell
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_format ⇒ Object
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(, *args) answer = @shell.ask(, *args) = args.last.is_a?(Hash) ? args.pop : {} say("\n") unless .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_stdout ⇒ Object
47 48 49 |
# File 'lib/uffizzi/shell.rb', line 47 def disable_stdout $stdout = StringIO.new end |
#enable_stdout ⇒ Object
51 52 53 |
# File 'lib/uffizzi/shell.rb', line 51 def enable_stdout $stdout = IO.new(1, 'w') end |
#last_message ⇒ Object
43 44 45 |
# File 'lib/uffizzi/shell.rb', line 43 def @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 |
#print_in_columns(messages) ⇒ Object
28 29 30 |
# File 'lib/uffizzi/shell.rb', line 28 def print_in_columns() @shell.print_in_columns() end |
#print_table(table_data) ⇒ Object
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() @shell.say(()) end |
#say_error_and_exit(message) ⇒ Object
24 25 26 |
# File 'lib/uffizzi/shell.rb', line 24 def say_error_and_exit() raise ExitError.new(()) end |
#stdout_pipe? ⇒ Boolean
55 56 57 |
# File 'lib/uffizzi/shell.rb', line 55 def stdout_pipe? $stdout.stat.pipe? end |