Module: Arli::Helpers::Output
- Included in:
- Actions::Action, CLI::App, CLI::CommandFinder, Commands::Base, SystemCommands, Library::Installer, Library::MultiVersion
- Defined in:
- lib/arli/helpers/output.rb
Constant Summary collapse
- CHAR_FAILURE =
'✖'.red
- CHAR_SUCCESS =
'✔'.green
Class Attribute Summary collapse
-
.cursor ⇒ Object
Returns the value of attribute cursor.
-
.enabled ⇒ Object
Returns the value of attribute enabled.
Class Method Summary collapse
Instance Method Summary collapse
-
#___(msg = nil, newline = false) ⇒ Object
Shortcuts disabled in tests.
- #__p(*args) ⇒ Object
- #__pf(*args) ⇒ Object
- #__pt(*args) ⇒ Object
- #abort? ⇒ Boolean
- #action_fail(action, exception) ⇒ Object
- #action_ok(action) ⇒ Object
- #backup? ⇒ Boolean
- #cursor ⇒ Object
- #debug(msg) ⇒ Object
- #debug? ⇒ Boolean
- #error(msg, exception = nil) ⇒ Object
- #fuck ⇒ Object
- #header(command: nil) ⇒ Object
- #hr ⇒ Object
- #indent_cursor(value = 40) ⇒ Object
- #info(msg, header = nil) ⇒ Object
- #ok ⇒ Object
- #overwrite? ⇒ Boolean
- #print_action_failure(short, verbose = nil) ⇒ Object
- #print_action_starting(action_name) ⇒ Object
- #print_action_success(short, verbose = nil) ⇒ Object
- #print_target_dir(d, verb = 'installed') ⇒ Object
- #quiet? ⇒ Boolean
- #raise_invalid_arli_command!(cmd, e = nil) ⇒ Object
- #report_exception(e, header = nil) ⇒ Object
-
#verbose? ⇒ Boolean
Some shortcuts.
Class Attribute Details
.cursor ⇒ Object
Returns the value of attribute cursor.
12 13 14 |
# File 'lib/arli/helpers/output.rb', line 12 def cursor @cursor end |
.enabled ⇒ Object
Returns the value of attribute enabled.
12 13 14 |
# File 'lib/arli/helpers/output.rb', line 12 def enabled @enabled end |
Class Method Details
.disable! ⇒ Object
22 23 24 |
# File 'lib/arli/helpers/output.rb', line 22 def disable! self.enabled = false end |
.enable! ⇒ Object
14 15 16 |
# File 'lib/arli/helpers/output.rb', line 14 def enable! self.enabled = true end |
.enabled? ⇒ Boolean
18 19 20 |
# File 'lib/arli/helpers/output.rb', line 18 def enabled? self.enabled end |
Instance Method Details
#___(msg = nil, newline = false) ⇒ Object
Shortcuts disabled in tests
74 75 76 77 78 |
# File 'lib/arli/helpers/output.rb', line 74 def ___(msg = nil, newline = false) return unless Arli::Helpers::Output.enabled? __pf msg if msg __pt if newline end |
#__p(*args) ⇒ Object
84 85 86 |
# File 'lib/arli/helpers/output.rb', line 84 def __p(*args) print(*args) if Arli::Helpers::Output.enabled? end |
#__pf(*args) ⇒ Object
88 89 90 |
# File 'lib/arli/helpers/output.rb', line 88 def __pf(*args) printf(*args) if Arli::Helpers::Output.enabled? end |
#__pt(*args) ⇒ Object
80 81 82 |
# File 'lib/arli/helpers/output.rb', line 80 def __pt(*args) puts(*args) if Arli::Helpers::Output.enabled? end |
#abort? ⇒ Boolean
179 180 181 |
# File 'lib/arli/helpers/output.rb', line 179 def abort? config.if_exists.abort end |
#action_fail(action, exception) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/arli/helpers/output.rb', line 126 def action_fail(action, exception) print_action_failure(action.class.short_name, "#{action.class.short_name} failed with #{exception.message.red}\n" + "Action Description: #{action.class.description}") raise(exception) end |
#action_ok(action) ⇒ Object
133 134 135 |
# File 'lib/arli/helpers/output.rb', line 133 def action_ok(action) print_action_success(action.action_name) end |
#backup? ⇒ Boolean
175 176 177 |
# File 'lib/arli/helpers/output.rb', line 175 def backup? config.if_exists.backup end |
#cursor ⇒ Object
32 33 34 |
# File 'lib/arli/helpers/output.rb', line 32 def cursor Arli::Helpers::Output.cursor end |
#debug(msg) ⇒ Object
41 42 43 44 |
# File 'lib/arli/helpers/output.rb', line 41 def debug(msg) __pf('%-20s', header.blue) if header __pf((header ? ' : ' : '') + msg + "\n") if msg end |
#debug? ⇒ Boolean
183 184 185 |
# File 'lib/arli/helpers/output.rb', line 183 def debug? config.debug end |
#error(msg, exception = nil) ⇒ Object
46 47 48 49 |
# File 'lib/arli/helpers/output.rb', line 46 def error(msg, exception = nil) __pf "#{msg.to_s.red}\n" if msg __pf "#{exception.inspect.red}\n\n" if exception end |
#fuck ⇒ Object
141 142 143 |
# File 'lib/arli/helpers/output.rb', line 141 def fuck ___ " #{CHAR_FAILURE} " end |
#header(command: nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/arli/helpers/output.rb', line 145 def header(command: nil) out = "\n#{hr}\n" out << "Arli (#{::Arli::VERSION.yellow})" out << ", Command: #{command.name.to_s.magenta.bold}" if command if command && command.params && Arli.config.verbose out << "\n#{command.params.to_s.blue}\n" end out << command.additional_info if command.respond_to?(:additional_info) out << "Library Path: #{Arli.default_library_path.green}\n" out << "#{hr}" info out end |
#hr ⇒ Object
158 159 160 |
# File 'lib/arli/helpers/output.rb', line 158 def hr ('—' * ((ENV['COLUMNS'] || 70).to_i - 1)).red.dark end |
#indent_cursor(value = 40) ⇒ Object
187 188 189 |
# File 'lib/arli/helpers/output.rb', line 187 def indent_cursor(value = 40) ___ cursor.column(value) end |
#info(msg, header = nil) ⇒ Object
36 37 38 39 |
# File 'lib/arli/helpers/output.rb', line 36 def info(msg, header = nil) __pf('%-20s', header.blue) if header __pf((header ? ' : ' : '') + msg + "\n") if msg end |
#ok ⇒ Object
137 138 139 |
# File 'lib/arli/helpers/output.rb', line 137 def ok ___ " #{CHAR_SUCCESS} " end |
#overwrite? ⇒ Boolean
171 172 173 |
# File 'lib/arli/helpers/output.rb', line 171 def overwrite? config.if_exists.overwrite end |
#print_action_failure(short, verbose = nil) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/arli/helpers/output.rb', line 117 def print_action_failure(short, verbose = nil) if verbose? && !quiet? indent_cursor ___ "⇨ #{verbose || short} #{CHAR_FAILURE}\n" elsif !quiet? ___ "#{short} #{CHAR_FAILURE} " end end |
#print_action_starting(action_name) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/arli/helpers/output.rb', line 97 def print_action_starting(action_name) if verbose? indent_cursor ___ "⇨ #{action_name.yellow} ... " end if block_given? yield ok if verbose? end end |
#print_action_success(short, verbose = nil) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/arli/helpers/output.rb', line 108 def print_action_success(short, verbose = nil) if verbose? && !quiet? indent_cursor ___ "⇨ #{verbose || short} #{CHAR_SUCCESS}" elsif !quiet? ___ "#{short} #{CHAR_SUCCESS} " end end |
#print_target_dir(d, verb = 'installed') ⇒ Object
93 94 95 |
# File 'lib/arli/helpers/output.rb', line 93 def print_target_dir(d, verb = 'installed') print_action_success(d.green, "#{verb} #{d.green} ") end |
#quiet? ⇒ Boolean
167 168 169 |
# File 'lib/arli/helpers/output.rb', line 167 def quiet? config.quiet end |
#raise_invalid_arli_command!(cmd, e = nil) ⇒ Object
69 70 71 |
# File 'lib/arli/helpers/output.rb', line 69 def raise_invalid_arli_command!(cmd, e = nil) raise Arli::Errors::InvalidCommandError.new(cmd) end |
#report_exception(e, header = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/arli/helpers/output.rb', line 51 def report_exception(e, header = nil) if header __pf header.bold.yellow + ': ' else __pf 'Error: '.bold.red end error e. if (e && e.respond_to?(:message)) if e && Arli.config.trace __pf "\n" __pf 'Top 10 stack trace'.bold.yellow + "\n" __pf e.backtrace.reverse[-10..-1].join("\n").red + "\n" elsif e __pf "\nUse -t (--trace) for detailed exception\n" + "or -D (--debug) to print Arli config\n" end raise(e) end |
#verbose? ⇒ Boolean
Some shortcuts
163 164 165 |
# File 'lib/arli/helpers/output.rb', line 163 def verbose? config.verbose && !quiet? end |