@@ -18,7 +18,7 @@ import (
1818 "path/filepath"
1919)
2020
21- func CreateLockFile (lockFiles []string , cmdArgs []string , lockGenCmd []string , forced bool ) {
21+ func CreateLockFile (lockFiles []string , cmdArgs []string , lockGenCmd []string , outputFileName string , forced bool ) {
2222
2323 path := "."
2424 if len (cmdArgs ) > 0 {
@@ -42,7 +42,7 @@ func CreateLockFile(lockFiles []string, cmdArgs []string, lockGenCmd []string, f
4242
4343 }
4444 }
45- genLock (lockGenCmd , absPath )
45+ genLock (lockGenCmd , absPath , outputFileName )
4646
4747}
4848
@@ -67,14 +67,28 @@ func DoesFileExists(absPath string) bool {
6767 return false
6868}
6969
70- func genLock (lockGenCmd []string , absPath string ) {
70+ func genLock (lockGenCmd []string , absPath string , outputFileName string ) {
7171 fmt .Printf ("Generating lockfile using '%s'\n " , lockGenCmd )
7272
7373 // #nosec G204
7474 command := exec .Command (lockGenCmd [0 ], lockGenCmd [1 :]... )
7575 command .Dir = absPath
76- command .Stdout = os .Stdout
7776 command .Stderr = os .Stderr
77+ command .Stdout = os .Stdout
78+ if outputFileName != "" {
79+
80+ outputPath := filepath .Join (absPath , outputFileName )
81+
82+ // #nosec G304
83+ outputFile , err := os .Create (outputPath )
84+ if err != nil {
85+ fmt .Fprintln (os .Stderr , "Error: failed to create output file: " , err )
86+ os .Exit (1 )
87+ }
88+ defer outputFile .Close ()
89+
90+ command .Stdout = outputFile
91+ }
7892
7993 if err := command .Run (); err != nil {
8094 fmt .Fprintln (os .Stderr , "Error: Failed to generate lockfile: " , err )
0 commit comments