Skip to content

Commit 833348f

Browse files
committed
feat: Enhance schema comparison and output formatting
- Updated the `compareSchemas` function to utilize `any` type for improved type handling. - Introduced new utility functions for better array and property formatting, ensuring complex objects are displayed correctly in output. - Added validation for filter sections in the `runVersionsDiff` function to enhance error handling. - Expanded test coverage for formatting functions and array changes to ensure consistent output without raw map displays. - Improved overall readability and structure of the output for schema changes.
1 parent c198e32 commit 833348f

File tree

3 files changed

+815
-122
lines changed

3 files changed

+815
-122
lines changed

cmd/diff.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func newDiffCmd() *cobra.Command {
4343
# Diff two local yaml configuration files
4444
asconfig diff files aerospike1.yaml aerospike2.yaml
4545
# Diff a local .conf file against a running server
46-
asconfig diff server -h 127.0.0.1:3000 aerospike.conf`,
46+
asconfig diff server -h 127.0.0.1:3000 aerospike.conf
47+
# Compare configuration changes between versions
48+
asconfig diff versions 7.0.0 8.1.0
49+
# Compare configuration changes between versions and focus on specific configuration areas
50+
asconfig diff versions 7.0.0 8.0.0 --filter-path "logging,namespaces"`,
4751
RunE: func(cmd *cobra.Command, args []string) error {
4852
logger.Warn("Using legacy 'diff' subcommand. Use 'diff files' instead.")
4953
return runFileDiff(cmd, args)
@@ -130,13 +134,12 @@ func newDiffVersionsCmd() *cobra.Command {
130134
Use: "versions [flags] <version1> <version2>",
131135
Short: "Show configuration file difference between versions of the Aerospike server.",
132136
Long: `Compare configuration schemas between two Aerospike server versions to understand
133-
what changes when upgrading or downgrading. This command shows which configuration
134-
parameters are added, removed, or modified between versions in a detailed, human-readable format.
137+
what changes when upgrading or downgrading. This command shows which configuration
138+
parameters are added, removed, or modified between versions in a detailed, human-readable format.
135139
136-
The tool automatically orders versions chronologically, so you can specify them in any order.
137-
By default, detailed information is shown including property types, defaults, and descriptions.
138-
Use --compact to show only configuration names for a minimal view.
139-
Use --filter-path to focus on specific configuration sections.`,
140+
By default, detailed information is shown including property types, defaults, and descriptions.
141+
Use --compact to show only configuration names for a minimal view.
142+
Use --filter-path to focus on specific configuration sections.`,
140143
Example: `
141144
# Compare configuration changes between versions (detailed by default)
142145
asconfig diff versions 7.0.0 7.2.0
@@ -397,7 +400,7 @@ func runVersionsDiff(cmd *cobra.Command, args []string) error {
397400
return errors.Join(errInvalidSchemaVersion, fmt.Errorf("schema for version %s not found", version2))
398401
}
399402

400-
var schemaLower, schemaUpper map[string]interface{}
403+
var schemaLower, schemaUpper map[string]any
401404
if unmarshalErr := json.Unmarshal([]byte(schema1), &schemaLower); unmarshalErr != nil {
402405
return fmt.Errorf("failed to parse schema for version %s: %w", version1, unmarshalErr)
403406
}
@@ -424,6 +427,13 @@ func runVersionsDiff(cmd *cobra.Command, args []string) error {
424427
return fmt.Errorf("failed to compare schemas: %w", err)
425428
}
426429

430+
// Validate filter sections if provided
431+
if len(filterSections) > 0 {
432+
if err := validateFilterSections(filterSections, summary.Sections); err != nil {
433+
return err
434+
}
435+
}
436+
427437
// Output the results
428438
printChangeSummary(summary, DiffOptions{
429439
Verbose: verbose,

0 commit comments

Comments
 (0)