Module: Morpheus::Cli::ProcessesHelper
- Defined in:
- lib/morpheus/cli/mixins/processes_helper.rb
Overview
Mixin for Morpheus::Cli command classes Provides common methods for viewing process history
Class Method Summary collapse
Instance Method Summary collapse
-
#format_process_duration(process, time_format = "%H:%M:%S") ⇒ Object
format for either ETA/Duration.
-
#format_process_error(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell.
-
#format_process_output(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell.
- #format_process_status(process, return_color = cyan) ⇒ Object
- #print_process_details(process) ⇒ Object
- #print_process_event_details(process_event) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
7 8 9 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 7 def self.included(klass) klass.send :include, Morpheus::Cli::PrintHelper end |
Instance Method Details
#format_process_duration(process, time_format = "%H:%M:%S") ⇒ Object
format for either ETA/Duration
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 100 def format_process_duration(process, time_format="%H:%M:%S") out = "" if process['duration'] && process['duration'] > 0 out = format_duration_milliseconds(process['duration'], time_format) elsif process['statusEta'] && process['statusEta'] > 0 out = format_duration_milliseconds(process['statusEta'], time_format) elsif process['startDate'] && process['endDate'] out = format_duration(process['startDate'], process['endDate'], time_format) else "" end out end |
#format_process_error(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell
90 91 92 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 90 def format_process_error(process, max_length=20, return_color=cyan) truncate_string(process['error'].to_s.strip.gsub("\n", " "), max_length) end |
#format_process_output(process, max_length = 20, return_color = cyan) ⇒ Object
decolorize, remove newlines and truncate for table cell
95 96 97 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 95 def format_process_output(process, max_length=20, return_color=cyan) truncate_string(process['output'].to_s.strip.gsub("\n", " "), max_length) end |
#format_process_status(process, return_color = cyan) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 74 def format_process_status(process, return_color=cyan) out = "" status_string = process['status'].to_s if status_string == 'complete' out << "#{green}#{status_string.upcase}#{return_color}" elsif status_string == 'failed' out << "#{red}#{status_string.upcase}#{return_color}" elsif status_string == 'expired' out << "#{red}#{status_string.upcase}#{return_color}" else out << "#{cyan}#{status_string.upcase}#{return_color}" end out end |
#print_process_details(process) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 12 def print_process_details(process) description_cols = { "Process ID" => lambda {|it| it['id'] }, "Name" => lambda {|it| it['displayName'] }, "Description" => lambda {|it| it['description'] }, "Process Type" => lambda {|it| it['processType'] ? (it['processType']['name'] || it['processType']['code']) : it['processTypeName'] }, "Created By" => lambda {|it| it['createdBy'] ? (it['createdBy']['displayName'] || it['createdBy']['username']) : '' }, "Start Date" => lambda {|it| format_local_dt(it['startDate']) }, "End Date" => lambda {|it| format_local_dt(it['endDate']) }, "Duration" => lambda {|it| format_process_duration(it) }, "Status" => lambda {|it| format_process_status(it) }, # "# Events" => lambda {|it| (it['events'] || []).size() }, } print_description_list(description_cols, process) if process['error'] print_h2 "Error" print reset #puts format_process_error(process_event) puts process['error'].to_s.strip end if process['output'] print_h2 "Output" print reset #puts format_process_error(process_event) puts process['output'].to_s.strip end end |
#print_process_event_details(process_event) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/morpheus/cli/mixins/processes_helper.rb', line 42 def print_process_event_details(process_event) # process_event =~ process description_cols = { "Process ID" => lambda {|it| it['processId'] }, "Event ID" => lambda {|it| it['id'] }, "Name" => lambda {|it| it['displayName'] }, "Description" => lambda {|it| it['description'] }, "Process Type" => lambda {|it| it['processType'] ? (it['processType']['name'] || it['processType']['code']) : it['processTypeName'] }, "Created By" => lambda {|it| it['createdBy'] ? (it['createdBy']['displayName'] || it['createdBy']['username']) : '' }, "Start Date" => lambda {|it| format_local_dt(it['startDate']) }, "End Date" => lambda {|it| format_local_dt(it['endDate']) }, "Duration" => lambda {|it| format_process_duration(it) }, "Status" => lambda {|it| format_process_status(it) }, } print_description_list(description_cols, process_event) if process_event['error'] print_h2 "Error" print reset #puts format_process_error(process_event) puts process_event['error'].to_s.strip end if process_event['output'] print_h2 "Output" print reset #puts format_process_error(process_event) puts process_event['output'].to_s.strip end end |