<#56 Making every command output json (In the futu...
# flyte-github
c
#56 Making every command output json (In the future yaml too) Pull request opened by kumare3 ### PR Description #### Overview This pull request introduces significant improvements to the Flyte CLI and SDK around output formatting and JSON serialization. The goal is to make CLI output more flexible, scriptable, and user-friendly, especially for automation and integration with other tools. --- #### Key Changes 1. Output Format Option for CLI • Replaces the boolean --simple flag with a new --output-format (or -of) option. • Supports multiple formats: table (default), table-simple, and json. • All CLI commands that previously used get_table now use the new format function, allowing consistent output formatting based on user preference. 2. Common Formatting Utilities • Introduces a new format function in _common.py that handles table, simple table, and JSON output for iterable objects. • get_panel is updated to respect output format for consistency. 3. ToJSONMixin for Models • Adds a new ToJSONMixin class (in remote/_common.py) that provides to_dict and to_json methods. • All major API model classes (Project, Run, Task, Secret, Action, ActionDetails, ActionInputs, ActionOutputs, RunDetails, TaskDetails) now inherit from ToJSONMixin. • This enables easy and consistent JSON serialization for CLI output and programmatic use. 4. Improved List Commands • All list commands (e.g., flyte get projects, flyte get runs, flyte get tasks, etc.) now respect the --output-format option. • Limits for listing are more consistently handled (e.g., flyte get run/task now have a --limit option). 5. Codebase Modernization • Refactors all usages of simple argument to output_format. • Updates type annotations using Literal and typing_extensions.get_args for CLI option validation. --- #### Motivation • Provides a more scriptable CLI experience for users and automation by supporting JSON output. • Makes the CLI more flexible for different use cases (human-friendly tables, simple for scripting, JSON for parsing). • Unifies output formatting and serialization logic across the codebase for maintainability and consistency. --- #### Backward Compatibility • The --simple flag is removed and replaced by --output-format. The default remains a rich table, so most users will not notice a change unless they used --simple (who can now use --output-format table-simple). • All API models are backward compatible, now with additional methods for JSON serialization. --- #### How to Use • Human-readable table (default):
flyte get projects
• Simple table (for copy-pasting):
flyte get projects --output-format table-simple
• JSON output (for scripting/automation):
flyte get projects --output-format json
--- #### Example flyte get tasks --output-format json --limit 10 --- #### Additional Notes • All new output format logic is centralized, making future extensions (e.g., YAML, CSV) easy to add. • The ToJSONMixin is designed to work seamlessly with protobuf-based models as well as plain dataclasses. flyteorg/flyte-sdk