fix: enforce json output for az monitor metrics and aks tools #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces logic to ensure that all Azure CLI commands executed by our code default to JSON output unless an explicit output format is specified. This helps standardize command responses and makes downstream processing more predictable. The changes are implemented for both string-based and slice-based argument handling, with comprehensive unit tests added for each helper.
Output format enforcement:
ensureOutputFormatArgshelper tointernal/components/azaks/executor.goto append--output jsonto command-line arguments when no output format is specified, usingshlexfor robust argument parsing. [1] [2] [3]ensureOutputArghelper tointernal/components/monitor/handlers.gofor slice-based argument lists, ensuring--output jsonis present unless an output flag is already specified. [1] [2]Testing:
ensureOutputFormatArgsininternal/components/azaks/executor_test.goto cover various scenarios, including malformed input.ensureOutputArgininternal/components/monitor/handlers_test.goto verify correct behavior for different argument combinations.