Skip to content

Commit 863f619

Browse files
Merge pull request #8 from benjaminjackson/fix/webset-list-pretty-format
feat(cli): add enhanced pretty format for webset-list
2 parents 0565dc5 + 7e487be commit 863f619

11 files changed

Lines changed: 475 additions & 26 deletions

lib/exa/cli/formatters/enrichment_formatter.rb

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.format(enrichment, output_format)
99
when "json"
1010
JSON.generate(enrichment.to_h)
1111
when "pretty"
12-
JSON.pretty_generate(enrichment.to_h)
12+
format_as_pretty(enrichment)
1313
when "text"
1414
format_as_text(enrichment)
1515
when "toon"
@@ -24,7 +24,7 @@ def self.format_collection(collection, output_format)
2424
when "json"
2525
JSON.generate(collection.to_h)
2626
when "pretty"
27-
JSON.pretty_generate(collection.to_h)
27+
format_collection_as_pretty(collection)
2828
when "text"
2929
format_collection_as_text(collection)
3030
when "toon"
@@ -34,6 +34,31 @@ def self.format_collection(collection, output_format)
3434
end
3535
end
3636

37+
def self.format_as_pretty(enrichment)
38+
lines = []
39+
lines << "Enrichment ID: #{enrichment.id}"
40+
lines << "Webset ID: #{enrichment.webset_id}" if enrichment.webset_id
41+
lines << "Status: #{enrichment.status}"
42+
lines << "Title: #{enrichment.title}" if enrichment.title
43+
lines << "Description: #{enrichment.description}" if enrichment.description
44+
lines << "Format: #{enrichment.format}" if enrichment.format
45+
46+
if enrichment.options && !enrichment.options.empty?
47+
lines << ""
48+
lines << "Options (#{enrichment.options.length}):"
49+
enrichment.options.each do |option|
50+
lines << " • #{option['label']}" if option['label']
51+
end
52+
end
53+
54+
lines << ""
55+
lines << "Created: #{enrichment.created_at}" if enrichment.created_at
56+
lines << "Updated: #{enrichment.updated_at}" if enrichment.updated_at
57+
58+
lines.join("\n")
59+
end
60+
private_class_method :format_as_pretty
61+
3762
def self.format_as_text(enrichment)
3863
lines = []
3964
lines << "Enrichment: #{enrichment.id}"
@@ -57,6 +82,33 @@ def self.format_as_text(enrichment)
5782
end
5883
private_class_method :format_as_text
5984

85+
def self.format_collection_as_pretty(collection)
86+
lines = []
87+
lines << "Enrichments (#{collection.data.length} items)"
88+
lines << ""
89+
90+
collection.data.each_with_index do |enr, idx|
91+
lines << "" if idx > 0 # Blank line between enrichments
92+
93+
lines << "Enrichment ID: #{enr['id']}"
94+
lines << "Webset ID: #{enr['websetId']}" if enr['websetId']
95+
lines << "Status: #{enr['status']}"
96+
lines << "Title: #{enr['title']}" if enr['title']
97+
lines << "Description: #{enr['description']}" if enr['description']
98+
lines << "Format: #{enr['format']}" if enr['format']
99+
lines << "Created: #{enr['createdAt']}" if enr['createdAt']
100+
lines << "Updated: #{enr['updatedAt']}" if enr['updatedAt']
101+
end
102+
103+
if collection.has_more
104+
lines << ""
105+
lines << "Next Cursor: #{collection.next_cursor}"
106+
end
107+
108+
lines.join("\n")
109+
end
110+
private_class_method :format_collection_as_pretty
111+
60112
def self.format_collection_as_text(collection)
61113
lines = ["Enrichments (#{collection.data.length} items):"]
62114
collection.data.each do |enr|

lib/exa/cli/formatters/import_formatter.rb

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.format(import, output_format)
99
when "json"
1010
JSON.generate(import.to_h)
1111
when "pretty"
12-
JSON.pretty_generate(import.to_h)
12+
format_as_pretty(import)
1313
when "text"
1414
format_as_text(import)
1515
when "toon"
@@ -24,7 +24,7 @@ def self.format_collection(collection, output_format)
2424
when "json"
2525
JSON.generate(collection.to_h)
2626
when "pretty"
27-
JSON.pretty_generate(collection.to_h)
27+
format_collection_as_pretty(collection)
2828
when "text"
2929
format_collection_as_text(collection)
3030
when "toon"
@@ -34,6 +34,43 @@ def self.format_collection(collection, output_format)
3434
end
3535
end
3636

37+
def self.format_as_pretty(import)
38+
lines = []
39+
lines << "Import ID: #{import.id}"
40+
lines << "Status: #{import.status}"
41+
lines << "Title: #{import.title}" if import.title
42+
lines << "Format: #{import.format}" if import.format
43+
44+
if import.entity
45+
entity_type = import.entity['type'] || import.entity[:type]
46+
lines << "Entity Type: #{entity_type}" if entity_type
47+
end
48+
49+
lines << "Count: #{import.count}" if import.count
50+
51+
if import.failed?
52+
lines << ""
53+
lines << "Failure:"
54+
lines << " Reason: #{import.failed_reason}" if import.failed_reason
55+
lines << " Message: #{import.failed_message}" if import.failed_message
56+
lines << " Failed At: #{import.failed_at}" if import.failed_at
57+
end
58+
59+
if import.upload_url
60+
lines << ""
61+
lines << "Upload:"
62+
lines << " URL: #{import.upload_url}"
63+
lines << " Valid Until: #{import.upload_valid_until}" if import.upload_valid_until
64+
end
65+
66+
lines << ""
67+
lines << "Created: #{import.created_at}" if import.created_at
68+
lines << "Updated: #{import.updated_at}" if import.updated_at
69+
70+
lines.join("\n")
71+
end
72+
private_class_method :format_as_pretty
73+
3774
def self.format_as_text(import)
3875
lines = []
3976
lines << "Import: #{import.id}"
@@ -68,6 +105,37 @@ def self.format_as_text(import)
68105
end
69106
private_class_method :format_as_text
70107

108+
def self.format_collection_as_pretty(collection)
109+
lines = []
110+
lines << "Imports (#{collection.data.length} items)"
111+
lines << ""
112+
113+
collection.data.each_with_index do |imp, idx|
114+
lines << "" if idx > 0 # Blank line between imports
115+
116+
lines << "Import ID: #{imp.id}"
117+
lines << "Status: #{imp.status}"
118+
lines << "Title: #{imp.title}" if imp.title
119+
lines << "Format: #{imp.format}" if imp.format
120+
lines << "Entity Type: #{imp.entity['type']}" if imp.entity && imp.entity['type']
121+
lines << "Count: #{imp.count}" if imp.count
122+
lines << "Created: #{imp.created_at}" if imp.created_at
123+
lines << "Updated: #{imp.updated_at}" if imp.updated_at
124+
125+
if imp.status == 'failed'
126+
lines << "Failed Reason: #{imp.failed_reason}" if imp.failed_reason
127+
end
128+
end
129+
130+
if collection.has_more
131+
lines << ""
132+
lines << "Next Cursor: #{collection.next_cursor}"
133+
end
134+
135+
lines.join("\n")
136+
end
137+
private_class_method :format_collection_as_pretty
138+
71139
def self.format_collection_as_text(collection)
72140
lines = ["Imports (#{collection.data.length} items):"]
73141
collection.data.each do |imp|

lib/exa/cli/formatters/monitor_formatter.rb

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.format(monitor, output_format)
99
when "json"
1010
JSON.generate(monitor.to_h)
1111
when "pretty"
12-
JSON.pretty_generate(monitor.to_h)
12+
format_as_pretty(monitor)
1313
when "text"
1414
format_as_text(monitor)
1515
when "toon"
@@ -24,7 +24,7 @@ def self.format_collection(collection, output_format)
2424
when "json"
2525
JSON.generate(collection.to_h)
2626
when "pretty"
27-
JSON.pretty_generate(collection.to_h)
27+
format_collection_as_pretty(collection)
2828
when "text"
2929
format_collection_as_text(collection)
3030
when "toon"
@@ -34,6 +34,35 @@ def self.format_collection(collection, output_format)
3434
end
3535
end
3636

37+
def self.format_as_pretty(monitor)
38+
lines = []
39+
lines << "Monitor ID: #{monitor.id}"
40+
lines << "Webset ID: #{monitor.webset_id}" if monitor.webset_id
41+
lines << "Status: #{monitor.status}"
42+
43+
if monitor.cadence
44+
lines << ""
45+
lines << "Cadence:"
46+
lines << " Cron: #{monitor.cadence['cron']}" if monitor.cadence['cron']
47+
lines << " Timezone: #{monitor.cadence['timezone']}" if monitor.cadence['timezone']
48+
end
49+
50+
if monitor.behavior
51+
lines << ""
52+
lines << "Behavior:"
53+
lines << " Type: #{monitor.behavior['type']}" if monitor.behavior['type']
54+
lines << " Query: #{monitor.behavior['query']}" if monitor.behavior['query']
55+
lines << " Count: #{monitor.behavior['count']}" if monitor.behavior['count']
56+
end
57+
58+
lines << ""
59+
lines << "Created: #{monitor.created_at}" if monitor.created_at
60+
lines << "Updated: #{monitor.updated_at}" if monitor.updated_at
61+
62+
lines.join("\n")
63+
end
64+
private_class_method :format_as_pretty
65+
3766
def self.format_as_text(monitor)
3867
lines = []
3968
lines << "Monitor: #{monitor.id}"
@@ -60,6 +89,40 @@ def self.format_as_text(monitor)
6089
end
6190
private_class_method :format_as_text
6291

92+
def self.format_collection_as_pretty(collection)
93+
lines = []
94+
lines << "Monitors (#{collection.data.length} items)"
95+
lines << ""
96+
97+
collection.data.each_with_index do |mon, idx|
98+
lines << "" if idx > 0 # Blank line between monitors
99+
100+
lines << "Monitor ID: #{mon['id']}"
101+
lines << "Webset ID: #{mon['websetId']}" if mon['websetId']
102+
lines << "Status: #{mon['status']}"
103+
104+
if mon['cadence']
105+
lines << "Cron: #{mon['cadence']['cron']}" if mon['cadence']['cron']
106+
lines << "Timezone: #{mon['cadence']['timezone']}" if mon['cadence']['timezone']
107+
end
108+
109+
if mon['behavior']
110+
lines << "Query: #{mon['behavior']['query']}" if mon['behavior']['query']
111+
end
112+
113+
lines << "Created: #{mon['createdAt']}" if mon['createdAt']
114+
lines << "Updated: #{mon['updatedAt']}" if mon['updatedAt']
115+
end
116+
117+
if collection.has_more
118+
lines << ""
119+
lines << "Next Cursor: #{collection.next_cursor}"
120+
end
121+
122+
lines.join("\n")
123+
end
124+
private_class_method :format_collection_as_pretty
125+
63126
def self.format_collection_as_text(collection)
64127
lines = ["Monitors (#{collection.data.length} items):"]
65128
collection.data.each do |mon|

lib/exa/cli/formatters/monitor_run_formatter.rb

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def self.format(monitor_run, output_format)
99
when "json"
1010
JSON.generate(monitor_run.to_h)
1111
when "pretty"
12-
JSON.pretty_generate(monitor_run.to_h)
12+
format_as_pretty(monitor_run)
1313
when "text"
1414
format_as_text(monitor_run)
1515
when "toon"
@@ -24,7 +24,7 @@ def self.format_collection(collection, output_format)
2424
when "json"
2525
JSON.generate(collection.to_h)
2626
when "pretty"
27-
JSON.pretty_generate(collection.to_h)
27+
format_collection_as_pretty(collection)
2828
when "text"
2929
format_collection_as_text(collection)
3030
when "toon"
@@ -34,6 +34,27 @@ def self.format_collection(collection, output_format)
3434
end
3535
end
3636

37+
def self.format_as_pretty(monitor_run)
38+
lines = []
39+
lines << "Monitor Run ID: #{monitor_run.id}"
40+
lines << "Monitor ID: #{monitor_run.monitor_id}" if monitor_run.monitor_id
41+
lines << "Status: #{monitor_run.status}"
42+
43+
lines << ""
44+
lines << "Created: #{monitor_run.created_at}" if monitor_run.created_at
45+
lines << "Updated: #{monitor_run.updated_at}" if monitor_run.updated_at
46+
lines << "Completed: #{monitor_run.completed_at}" if monitor_run.completed_at
47+
48+
if monitor_run.failed?
49+
lines << ""
50+
lines << "Failed: #{monitor_run.failed_at}" if monitor_run.failed_at
51+
lines << "Reason: #{monitor_run.failed_reason}" if monitor_run.failed_reason
52+
end
53+
54+
lines.join("\n")
55+
end
56+
private_class_method :format_as_pretty
57+
3758
def self.format_as_text(monitor_run)
3859
lines = []
3960
lines << "Monitor Run: #{monitor_run.id}"
@@ -53,6 +74,36 @@ def self.format_as_text(monitor_run)
5374
end
5475
private_class_method :format_as_text
5576

77+
def self.format_collection_as_pretty(collection)
78+
lines = []
79+
lines << "Monitor Runs (#{collection.data.length} items)"
80+
lines << ""
81+
82+
collection.data.each_with_index do |run, idx|
83+
lines << "" if idx > 0 # Blank line between runs
84+
85+
lines << "Monitor Run ID: #{run['id']}"
86+
lines << "Monitor ID: #{run['monitorId']}" if run['monitorId']
87+
lines << "Status: #{run['status']}"
88+
lines << "Created: #{run['createdAt']}" if run['createdAt']
89+
lines << "Updated: #{run['updatedAt']}" if run['updatedAt']
90+
lines << "Completed: #{run['completedAt']}" if run['completedAt']
91+
92+
if run['status'] == 'failed'
93+
lines << "Failed: #{run['failedAt']}" if run['failedAt']
94+
lines << "Reason: #{run['failedReason']}" if run['failedReason']
95+
end
96+
end
97+
98+
if collection.has_more
99+
lines << ""
100+
lines << "Next Cursor: #{collection.next_cursor}"
101+
end
102+
103+
lines.join("\n")
104+
end
105+
private_class_method :format_collection_as_pretty
106+
56107
def self.format_collection_as_text(collection)
57108
lines = ["Monitor Runs (#{collection.data.length} items):"]
58109
collection.data.each do |run|

0 commit comments

Comments
 (0)