Skip to content

Commit

Permalink
[feat] output flag
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhenry committed Mar 3, 2023
1 parent ec0cb8c commit 9dff9b7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (

func main() {
// Define command-line flags
filePath := flag.String("file", "", "File to inject environment variables")
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.)")
flag.Bool("debug", false, "Enable debug mode")
flag.Parse()

// Load the file contents
fileBytes, err := ioutil.ReadFile(*filePath)
fileBytes, err := ioutil.ReadFile(*sourcePath)
if err != nil {
fmt.Println(err)
return
Expand All @@ -29,8 +30,12 @@ func main() {
fmt.Println(updatedContent)
}

if *outputPath == "" {
outputPath = sourcePath
}

// Write the updated content to the same file
err = ioutil.WriteFile(*filePath, []byte(updatedContent), 0644)
err = ioutil.WriteFile(*outputPath, []byte(updatedContent), 0644)
if err != nil {
fmt.Println(err)
return
Expand Down

0 comments on commit 9dff9b7

Please sign in to comment.