Class: Flow::Cli::Utils::CmdHelper
- Inherits:
-
Object
- Object
- Flow::Cli::Utils::CmdHelper
- Extended by:
- Forwardable
- Defined in:
- lib/flow/cli/utils/cmd_helper.rb
Instance Attribute Summary collapse
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Class Method Summary collapse
Instance Method Summary collapse
- #echo(log) ⇒ Object
-
#initialize ⇒ CmdHelper
constructor
A new instance of CmdHelper.
- #puts_error(log) ⇒ Object (also: #error, #echo_error)
- #puts_table(arr_dict, sorted_titles = nil) ⇒ Object
- #puts_warning(log) ⇒ Object (also: #warning, #echo_warning, #warn)
Constructor Details
#initialize ⇒ CmdHelper
Returns a new instance of CmdHelper.
9 10 11 12 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 9 def initialize @pastel = Pastel.new self.prompt = TTY::Prompt.new end |
Instance Attribute Details
#prompt ⇒ Object
Returns the value of attribute prompt.
8 9 10 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 8 def prompt @prompt end |
Class Method Details
.instance ⇒ Object
51 52 53 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 51 def instance new end |
Instance Method Details
#echo(log) ⇒ Object
16 17 18 19 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 16 def echo(log) @green ||= @pastel.green.bold.detach puts @green.call log end |
#puts_error(log) ⇒ Object Also known as: error, echo_error
34 35 36 37 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 34 def puts_error(log) @error ||= @pastel.red.bold.detach puts @error.call(log) end |
#puts_table(arr_dict, sorted_titles = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 21 def puts_table(arr_dict, sorted_titles = nil) sorted_titles = arr_dict.first.keys if sorted_titles.nil? table = TTY::Table.new header: sorted_titles arr_dict.each do |item| show_item = [] sorted_titles.each do |key| show_item << item[key] end table << show_item end puts table.render(:unicode) end |
#puts_warning(log) ⇒ Object Also known as: warning, echo_warning, warn
39 40 41 42 |
# File 'lib/flow/cli/utils/cmd_helper.rb', line 39 def puts_warning(log) @warning ||= @pastel.yellow.detach puts @warning.call(log) end |