MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / format_output

Function format_output

scripts/agents/devops/src/cli.py:226–269  ·  view source on GitHub ↗

Format output data based on format type.

(data, format_type='table')

Source from the content-addressed store, hash-verified

224
225
226def format_output(data, format_type='table'):
227 """Format output data based on format type."""
228 if format_type == 'json':
229 return json.dumps(data, indent=2, default=str)
230
231 # Simple table format for common data structures
232 if isinstance(data, list) and data and isinstance(data[0], dict):
233 # Get all unique keys
234 keys = set()
235 for item in data:
236 keys.update(item.keys())
237
238 # Prioritize common fields
239 priority_fields = ['id', 'name', 'instanceId', 'InstanceId', 'state', 'State', 'type', 'Type']
240 ordered_keys = [k for k in priority_fields if k in keys]
241 ordered_keys.extend([k for k in keys if k not in ordered_keys])
242
243 # Create table header
244 result = ' | '.join(ordered_keys) + '\n'
245 result += '-' * len(result) + '\n'
246
247 # Add rows
248 for item in data:
249 row = []
250 for key in ordered_keys:
251 value = item.get(key, '')
252 if isinstance(value, dict) and 'Name' in value:
253 value = value['Name']
254 row.append(str(value)[:30])
255 result += ' | '.join(row) + '\n'
256
257 return result
258
259 # For single dict objects
260 elif isinstance(data, dict):
261 result = ''
262 for key, value in data.items():
263 if isinstance(value, dict):
264 value = json.dumps(value, default=str)
265 result += f"{key}: {value}\n"
266 return result
267
268 # Default to string representation
269 return str(data)
270
271
272def handle_ec2_command(args):

Callers 2

handle_ec2_commandFunction · 0.70
handle_github_commandFunction · 0.70

Calls 1

getMethod · 0.65

Tested by

no test coverage detected