Module: Legate::CLI::OutputHelper
- Included in:
- AgentCommands, ToolCommands
- Defined in:
- lib/legate/cli/output_helper.rb
Overview
Helper module for CLI output control. Provides methods to conditionally output status messages and format results based on –quiet and –json flags.
Instance Method Summary collapse
-
#output_error(error, metadata: {}) ⇒ Object
Output error (JSON format in –json mode, otherwise text to stderr).
-
#output_result(data, metadata: {}, format_method: nil) ⇒ Object
Output final result (JSON format in –json mode, otherwise uses format_method or default).
-
#status_message(message, color = nil) ⇒ Object
Write status/progress message (suppressed in quiet or json mode).
Instance Method Details
#output_error(error, metadata: {}) ⇒ Object
Output error (JSON format in –json mode, otherwise text to stderr)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legate/cli/output_helper.rb', line 38 def output_error(error, metadata: {}) if json_mode? error_data = { status: 'error', error_class: error.is_a?(Exception) ? error.class.name : 'Error', error_message: error.is_a?(Exception) ? error. : error.to_s } error_data.merge!() unless .empty? puts JSON.generate(error_data) else = error.is_a?(Exception) ? "#{error.class} - #{error.}" : error.to_s say , :red end end |
#output_result(data, metadata: {}, format_method: nil) ⇒ Object
Output final result (JSON format in –json mode, otherwise uses format_method or default)
25 26 27 28 29 30 31 32 33 |
# File 'lib/legate/cli/output_helper.rb', line 25 def output_result(data, metadata: {}, format_method: nil) if json_mode? output_json(data, ) elsif format_method && respond_to?(format_method, true) send(format_method, data) else say data.inspect end end |
#status_message(message, color = nil) ⇒ Object
Write status/progress message (suppressed in quiet or json mode)
15 16 17 18 19 |
# File 'lib/legate/cli/output_helper.rb', line 15 def (, color = nil) return if quiet_mode? say , color end |