Skip to content

Commit 4d30ffc

Browse files
CopilotBaseMax
andcommitted
Complete implementation of go-config-diff utility
Co-authored-by: BaseMax <2658040+BaseMax@users.noreply.github.com>
1 parent 34d1b52 commit 4d30ffc

19 files changed

Lines changed: 1778 additions & 1 deletion

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Dependency directories
15+
vendor/
16+
17+
# Go workspace file
18+
go.work
19+
20+
# Build output
21+
go-config-diff
22+
23+
# IDE
24+
.idea/
25+
.vscode/
26+
*.swp
27+
*.swo
28+
*~
29+
30+
# OS
31+
.DS_Store
32+
Thumbs.db

README.md

Lines changed: 227 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,228 @@
11
# 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

examples/config1.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[server]
2+
host = localhost
3+
port = 8080
4+
ssl = true
5+
6+
[database]
7+
host = db.example.com
8+
port = 5432
9+
name = myapp
10+
username = admin
11+
password = secret123
12+
13+
[settings]
14+
timeout = 30
15+
retries = 3
16+
debug = false

examples/config1.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"server": {
3+
"host": "localhost",
4+
"port": 8080,
5+
"ssl": true
6+
},
7+
"database": {
8+
"host": "db.example.com",
9+
"port": 5432,
10+
"name": "myapp",
11+
"credentials": {
12+
"username": "admin",
13+
"password": "secret123"
14+
}
15+
},
16+
"features": [
17+
"authentication",
18+
"logging",
19+
"monitoring"
20+
],
21+
"settings": {
22+
"timeout": 30,
23+
"retries": 3,
24+
"debug": false
25+
}
26+
}

examples/config1.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[server]
2+
host = "localhost"
3+
port = 8080
4+
ssl = true
5+
6+
[database]
7+
host = "db.example.com"
8+
port = 5432
9+
name = "myapp"
10+
11+
[database.credentials]
12+
username = "admin"
13+
password = "secret123"
14+
15+
[[features]]
16+
name = "authentication"
17+
18+
[[features]]
19+
name = "logging"
20+
21+
[[features]]
22+
name = "monitoring"
23+
24+
[settings]
25+
timeout = 30
26+
retries = 3
27+
debug = false

examples/config1.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server:
2+
host: localhost
3+
port: 8080
4+
ssl: true
5+
database:
6+
host: db.example.com
7+
port: 5432
8+
name: myapp
9+
credentials:
10+
username: admin
11+
password: secret123
12+
features:
13+
- authentication
14+
- logging
15+
- monitoring
16+
settings:
17+
timeout: 30
18+
retries: 3
19+
debug: false

examples/config2.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[server]
2+
host = localhost
3+
port = 8080
4+
ssl = true
5+
timeout = 60
6+
7+
[database]
8+
host = db.example.com
9+
port = 5432
10+
name = myapp_prod
11+
username = admin
12+
password = newsecret456
13+
14+
[settings]
15+
timeout = 45
16+
retries = 5
17+
debug = true

0 commit comments

Comments
 (0)