@@ -10,34 +10,35 @@ import (
10
10
"github.com/bitfield/script"
11
11
)
12
12
13
- func ReplaceTokens (inputFilePath , outputFilePath , repoHost , repoOrg , repoName , newRepo string ){
13
+ // ReplaceTokens replaces tokens in input file and outputs to new file
14
+ func ReplaceTokens (inputFilePath , outputFilePath , repoHost , repoOrg , repoName , newRepo string ) {
14
15
parts := strings .Split (newRepo , "/" )
15
16
newRepoHost := parts [0 ]
16
17
newRepoOrg := parts [1 ]
17
18
newRepoName := parts [2 ]
18
19
log .Printf ("repoHost: %s, repoOrg: %s, repoName: %s, newRepoHost: %s, newRepoOrg: %s, newRepoName: %s\n " , repoHost , repoOrg , repoName , newRepoHost , newRepoOrg , newRepoName )
19
20
inplace := false
20
21
21
- if outputFilePath == "" {
22
+ if outputFilePath == "" {
22
23
inplace = true
23
- tempFileH , err := ioutil .TempFile (filepath .Dir (inputFilePath ),"" )
24
- if err != nil {
25
- log .Fatal (err .Error ())
24
+ tempFileH , err := ioutil .TempFile (filepath .Dir (inputFilePath ), "" )
25
+ if err != nil {
26
+ log .Fatal (err .Error ())
26
27
}
27
28
outputFilePath = tempFileH .Name ()
28
29
}
29
30
_ , err := script .File (inputFilePath ).Replace (repoHost , newRepoHost ).Replace (repoOrg , newRepoOrg ).Replace (repoName , newRepoName ).WriteFile (outputFilePath )
30
31
31
- if err != nil {
32
- log .Fatal (err .Error ())
32
+ if err != nil {
33
+ log .Fatal (err .Error ())
33
34
}
34
35
35
36
if inplace {
36
- script .File (outputFilePath ).Stdout ()
37
- log .Printf ("Moving %s to %s\n " , outputFilePath , inputFilePath )
38
- e := os .Rename (outputFilePath , inputFilePath )
39
- if e != nil {
40
- log .Fatal (e )
41
- }
37
+ script .File (outputFilePath ).Stdout ()
38
+ log .Printf ("Moving %s to %s\n " , outputFilePath , inputFilePath )
39
+ e := os .Rename (outputFilePath , inputFilePath )
40
+ if e != nil {
41
+ log .Fatal (e )
42
+ }
42
43
}
43
44
}
0 commit comments