|
1 | 1 | # go-config-diff |
2 | | -A semantic configuration comparison tool for infra and app configs. |
| 2 | + |
| 3 | +A semantic configuration comparison tool for infrastructure and application configs. Compare YAML, JSON, TOML, and INI files intelligently - detecting meaningful differences while ignoring formatting and ordering variations. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🎯 **Semantic Comparison**: Compares configuration semantics, not just text |
| 8 | +- 📝 **Multiple Formats**: Supports YAML, JSON, TOML, and INI files |
| 9 | +- 🎨 **Colored Output**: Beautiful, easy-to-read colored diffs in terminal |
| 10 | +- 📊 **Machine-Readable**: JSON output for integration with other tools |
| 11 | +- 🔄 **Order-Independent**: Ignores key ordering in maps/objects |
| 12 | +- 🧩 **Nested Structures**: Deep comparison of nested configurations |
| 13 | +- 📈 **Change Summary**: Quick overview of additions, removals, and modifications |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +### From Source |
| 18 | + |
| 19 | +```bash |
| 20 | +go install github.com/BaseMax/go-config-diff/cmd/go-config-diff@latest |
| 21 | +``` |
| 22 | + |
| 23 | +### Build Locally |
| 24 | + |
| 25 | +```bash |
| 26 | +git clone https://github.com/BaseMax/go-config-diff.git |
| 27 | +cd go-config-diff |
| 28 | +go build -o go-config-diff ./cmd/go-config-diff |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### Basic Usage |
| 34 | + |
| 35 | +```bash |
| 36 | +go-config-diff config1.yaml config2.yaml |
| 37 | +``` |
| 38 | + |
| 39 | +### Output Formats |
| 40 | + |
| 41 | +#### Colored Output (default) |
| 42 | +Displays changes with color-coded indicators: |
| 43 | +- 🟢 Green `+` for additions |
| 44 | +- 🔴 Red `-` for removals |
| 45 | +- 🟡 Yellow `~` for modifications |
| 46 | + |
| 47 | +```bash |
| 48 | +go-config-diff config1.yaml config2.yaml |
| 49 | +``` |
| 50 | + |
| 51 | +#### Plain Text Output |
| 52 | +For environments without color support: |
| 53 | + |
| 54 | +```bash |
| 55 | +go-config-diff -format=plain config1.json config2.json |
| 56 | +``` |
| 57 | + |
| 58 | +#### JSON Output |
| 59 | +Machine-readable format for automation: |
| 60 | + |
| 61 | +```bash |
| 62 | +go-config-diff -format=json config1.toml config2.toml |
| 63 | +``` |
| 64 | + |
| 65 | +### Show Summary |
| 66 | + |
| 67 | +Display a summary of changes: |
| 68 | + |
| 69 | +```bash |
| 70 | +go-config-diff -summary config1.ini config2.ini |
| 71 | +``` |
| 72 | + |
| 73 | +### Version Information |
| 74 | + |
| 75 | +```bash |
| 76 | +go-config-diff -version |
| 77 | +``` |
| 78 | + |
| 79 | +## Examples |
| 80 | + |
| 81 | +### YAML Comparison |
| 82 | + |
| 83 | +```bash |
| 84 | +$ go-config-diff examples/config1.yaml examples/config2.yaml |
| 85 | +~ database.credentials.password |
| 86 | + - "secret123" |
| 87 | + + "newsecret456" |
| 88 | +~ database.name |
| 89 | + - "myapp" |
| 90 | + + "myapp_prod" |
| 91 | ++ features[3] |
| 92 | + + "caching" |
| 93 | ++ server.timeout |
| 94 | + + 60 |
| 95 | +``` |
| 96 | + |
| 97 | +### JSON Output Format |
| 98 | + |
| 99 | +```bash |
| 100 | +$ go-config-diff -format=json examples/config1.json examples/config2.json |
| 101 | +{ |
| 102 | + "has_changes": true, |
| 103 | + "changes": [ |
| 104 | + { |
| 105 | + "type": "modified", |
| 106 | + "path": "database.name", |
| 107 | + "old_value": "myapp", |
| 108 | + "new_value": "myapp_prod" |
| 109 | + }, |
| 110 | + { |
| 111 | + "type": "added", |
| 112 | + "path": "server.timeout", |
| 113 | + "new_value": 60 |
| 114 | + } |
| 115 | + ] |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +### With Summary |
| 120 | + |
| 121 | +```bash |
| 122 | +$ go-config-diff -summary examples/config1.toml examples/config2.toml |
| 123 | +Summary: 2 added, 5 modified |
| 124 | + |
| 125 | +~ database.name |
| 126 | + - "myapp" |
| 127 | + + "myapp_prod" |
| 128 | ++ features[3] |
| 129 | + + {"name":"caching"} |
| 130 | +``` |
| 131 | + |
| 132 | +## Supported File Formats |
| 133 | + |
| 134 | +| Format | Extensions | Description | |
| 135 | +|--------|-----------|-------------| |
| 136 | +| YAML | `.yaml`, `.yml` | YAML Ain't Markup Language | |
| 137 | +| JSON | `.json` | JavaScript Object Notation | |
| 138 | +| TOML | `.toml` | Tom's Obvious, Minimal Language | |
| 139 | +| INI | `.ini`, `.conf` | Initialization files | |
| 140 | + |
| 141 | +## How It Works |
| 142 | + |
| 143 | +1. **Parse**: Each configuration file is parsed using format-specific parsers |
| 144 | +2. **Normalize**: Data is converted to a unified internal AST (Abstract Syntax Tree) |
| 145 | +3. **Compare**: Semantic comparison detects actual differences |
| 146 | +4. **Report**: Changes are formatted for human or machine consumption |
| 147 | + |
| 148 | +### Key Capabilities |
| 149 | + |
| 150 | +- **Semantic Comparison**: Compares actual values, not file formatting |
| 151 | +- **Type Awareness**: Understands different data types (strings, numbers, booleans, arrays, maps) |
| 152 | +- **Deep Traversal**: Compares nested structures at any depth |
| 153 | +- **Path Tracking**: Shows exact location of changes using dot notation |
| 154 | +- **Order Independence**: Map/object key ordering doesn't affect comparison |
| 155 | + |
| 156 | +## Exit Codes |
| 157 | + |
| 158 | +- `0`: No differences found |
| 159 | +- `1`: Differences found or error occurred |
| 160 | + |
| 161 | +## Command Line Options |
| 162 | + |
| 163 | +``` |
| 164 | +Usage: go-config-diff [options] <file1> <file2> |
| 165 | +
|
| 166 | +Options: |
| 167 | + -format string |
| 168 | + Output format: colored, plain, json (default "colored") |
| 169 | + -summary |
| 170 | + Show summary of changes |
| 171 | + -version |
| 172 | + Show version information |
| 173 | +``` |
| 174 | + |
| 175 | +## Use Cases |
| 176 | + |
| 177 | +- 🔧 **DevOps**: Compare configuration files across environments |
| 178 | +- 🚀 **CI/CD**: Validate configuration changes in pipelines |
| 179 | +- 🔍 **Auditing**: Review configuration differences for compliance |
| 180 | +- 🐛 **Debugging**: Identify configuration drift between systems |
| 181 | +- 📦 **Releases**: Verify configuration changes before deployment |
| 182 | + |
| 183 | +## Development |
| 184 | + |
| 185 | +### Running Tests |
| 186 | + |
| 187 | +```bash |
| 188 | +go test ./... -v |
| 189 | +``` |
| 190 | + |
| 191 | +### Project Structure |
| 192 | + |
| 193 | +``` |
| 194 | +go-config-diff/ |
| 195 | +├── cmd/ |
| 196 | +│ └── go-config-diff/ # CLI application |
| 197 | +│ └── main.go |
| 198 | +├── pkg/ |
| 199 | +│ ├── ast/ # Unified AST model |
| 200 | +│ │ ├── ast.go |
| 201 | +│ │ └── ast_test.go |
| 202 | +│ ├── parser/ # Format parsers |
| 203 | +│ │ ├── parser.go |
| 204 | +│ │ └── parser_test.go |
| 205 | +│ ├── diff/ # Comparison logic |
| 206 | +│ │ ├── diff.go |
| 207 | +│ │ └── diff_test.go |
| 208 | +│ └── output/ # Output formatters |
| 209 | +│ └── output.go |
| 210 | +├── examples/ # Sample config files |
| 211 | +└── README.md |
| 212 | +``` |
| 213 | + |
| 214 | +## License |
| 215 | + |
| 216 | +This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details. |
| 217 | + |
| 218 | +## Contributing |
| 219 | + |
| 220 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 221 | + |
| 222 | +## Author |
| 223 | + |
| 224 | +**Max Base** |
| 225 | + |
| 226 | +## Repository |
| 227 | + |
| 228 | +https://github.com/BaseMax/go-config-diff |
0 commit comments