-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (43 loc) · 1.18 KB
/
main.go
File metadata and controls
54 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
noColor bool
quiet bool
)
func main() {
var rootCmd = &cobra.Command{
Use: "env-diff [file1] [file2]",
Short: "Compare .env files and detect configuration differences",
Long: "Compare two .env files to identify missing, extra, or mismatched variables. Useful for pre-deployment checks and keeping env templates in sync.",
Args: cobra.ExactArgs(2),
Run: runDiff,
}
rootCmd.Flags().BoolVar(&noColor, "no-color", false, "Disable colored output")
rootCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "Only show summary, suppress detailed diff")
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func runDiff(cmd *cobra.Command, args []string) {
file1, file2 := args[0], args[1]
env1, err := ParseEnvFile(file1)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing %s: %v\n", file1, err)
os.Exit(1)
}
env2, err := ParseEnvFile(file2)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing %s: %v\n", file2, err)
os.Exit(1)
}
diff := CompareEnvFiles(env1, env2, file1, file2)
diff.Print(noColor, quiet)
if diff.HasDifferences() {
os.Exit(1)
}
}