Skip to content

refactor(output_format): support print key value list style for text format#63

Merged
aviatco merged 15 commits intomicrosoft:mainfrom
aviatco:dev/aviatcohen/supportPrintKeyValue
Nov 13, 2025
Merged

refactor(output_format): support print key value list style for text format#63
aviatco merged 15 commits intomicrosoft:mainfrom
aviatco:dev/aviatcohen/supportPrintKeyValue

Conversation

@aviatco
Copy link
Copy Markdown
Collaborator

@aviatco aviatco commented Nov 10, 2025

📥 Pull Request

✨ Description of new changes

Overview

This PR introduces a new output formatting option that displays data in a clean, human-readable key-value format instead of the default JSON structure. This enhancement improves the user experience by providing a more intuitive way to view command outputs.

Key Changes

  1. Core Infrastructure Updates
    FabricCLIOutput: Added show_key_value_pretty parameter to control the new formatting option
    print_output_format(): Enhanced the main output function to support the new formatting parameter
  2. New Key-Value Pretty Formatting Function
    _print_entries_key_value_pretty_style(): Implemented the core function that converts data into key-value format
    _format_key_to_pretty_name(): Added utility to transform snake_case and camelCase keys into readable "Title Case" format
  3. Smart Output Selection Logic
    Text Output Handler: Updated _print_output_format_result_text() to conditionally use key-value formatting when show_key_value_pretty=True
    Format Priority: JSON format takes precedence over key-value formatting to maintain backward compatibility
  4. Comprehensive Test Coverage
    Unit Tests: Added extensive test coverage including:
    Key-value pretty format activation and output verification
    JSON format precedence testing
    Input validation and error handling
    Key formatting transformation tests

Features

Output Format Examples

Before (JSON):

{
"logged_in": "true",
"account_name": "johndoe@example.com"
}

After (Key-Value Pretty):

Logged In: true
Account Name: johndoe@example.com

Key Formatting Intelligence

Converts snake_case → Title Case (e.g., logged_in → Logged In)
Converts camelCase → Spaced Title Case (e.g., accountName → Account Name)
Handles both single dictionaries and lists of dictionaries
Adds spacing between multiple entries for clarity
Integration Points
Works with existing print_output_format() calls throughout the codebase
Maintains full backward compatibility
Respects output format precedence (JSON > key-value > default)
Technical Implementation
Type Safety: Proper input validation with meaningful error messages
Performance: Minimal overhead, only processes data when explicitly enabled
Extensibility: Clean separation of concerns allows easy future enhancements
Error Handling: Graceful fallback for invalid input types

Testing

✅ Unit tests for all new functions and edge cases
✅ Integration tests with existing output pipeline
✅ Error handling and input validation coverage
✅ Format precedence verification

This enhancement provides users with a more readable alternative to JSON output while maintaining full compatibility with existing workflows and scripts.

## NOTE The flag only affects text output mode; JSON output ignores this setting.

@aviatco aviatco requested a review from a team as a code owner November 10, 2025 12:38
@aviatco aviatco changed the title feat: Support print in pritty key value style for text format feat: Support print in pretty key value style for text format Nov 10, 2025
@aviatco aviatco changed the title feat: Support print in pretty key value style for text format feat: Support print key value list style for text format Nov 11, 2025
@aviatco aviatco requested a review from ayeshurun November 11, 2025 07:36
@ayeshurun
Copy link
Copy Markdown
Collaborator

please add changie entry

ayeshurun
ayeshurun previously approved these changes Nov 11, 2025
@ayeshurun ayeshurun changed the title feat: Support print key value list style for text format feat(output_format): support print key value list style for text format Nov 11, 2025
@aviatco aviatco changed the title feat(output_format): support print key value list style for text format refactor(output_format): support print key value list style for text format Nov 12, 2025
ayeshurun
ayeshurun previously approved these changes Nov 12, 2025
ohadedry
ohadedry previously approved these changes Nov 12, 2025
ohadedry
ohadedry previously approved these changes Nov 13, 2025
@aviatco aviatco merged commit 6d25ecf into microsoft:main Nov 13, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants