-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (48 loc) · 1.48 KB
/
main.go
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
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"michaelhenry/envject/parser"
"michaelhenry/envject/value_encoders"
"os"
"strings"
)
func main() {
// Define command-line flags
sourcePath := flag.String("file", "", "File to inject the environment variables")
outputPath := flag.String("output", "", "The output file. (This creates a new file instead of overriding the original file.)")
ignore := flag.String("ignore", "", "Regex pattern to ignore.")
obfuscateFor := flag.String("obfuscate-for", "", "Obfuscate for particular programming language. (Example: swift)")
flag.Bool("debug", false, "Enable debug mode")
flag.Parse()
// Load the file contents
fileBytes, err := os.ReadFile(*sourcePath)
if err != nil {
fmt.Println(err)
return
}
var valueEncoder value_encoders.ValueEncoder
switch strings.ToLower(*obfuscateFor) {
case "swift":
valueEncoder = value_encoders.NewSwiftValueEncoder()
default:
valueEncoder = &value_encoders.RawValueEncoder{}
}
fileContent := string(fileBytes)
updatedContent := parser.ReplaceEnvVariables(fileContent, *ignore, valueEncoder)
// Check if debug flag is true
if flag.Lookup("debug").Value.String() == "true" {
fmt.Println(updatedContent)
}
if *outputPath == "" {
outputPath = sourcePath
}
// Write the updated content to the output file
err = os.WriteFile(*outputPath, []byte(updatedContent), 0644)
if err != nil {
fmt.Println(err)
return
}
// Print a success message
fmt.Println("Environment variables injected successfully!")
}