1
1
package scaffold
2
2
3
3
import (
4
- "bytes"
5
4
"context"
6
5
"errors"
7
6
"fmt"
@@ -70,15 +69,10 @@ func aquaGR(ctx context.Context, pkgName, rgFilePath string) error {
70
69
}
71
70
72
71
func aquaG (ctx context.Context , pkgName string ) error {
73
- outFile , err := os .OpenFile ("aqua-local.yaml" , os .O_APPEND | os .O_CREATE | os .O_WRONLY , filePermission )
74
- if err != nil {
75
- return fmt .Errorf ("open aqua-local.yaml: %w" , err )
76
- }
77
- defer outFile .Close ()
78
- fmt .Fprintf (os .Stderr , "+ aqua g %s >> aqua-local.yaml\n " , pkgName )
79
- cmd := exec .CommandContext (ctx , "aqua" , "g" , pkgName )
72
+ fmt .Fprintf (os .Stderr , "+ aqua g -o aqua-loca.yaml %s\n " , pkgName )
73
+ cmd := exec .CommandContext (ctx , "aqua" , "g" , "-o" , "aqua-local.yaml" , pkgName )
80
74
cmd .Stdin = os .Stdin
81
- cmd .Stdout = outFile
75
+ cmd .Stdout = os . Stdout
82
76
cmd .Stderr = os .Stderr
83
77
if err := cmd .Run (); err != nil {
84
78
return fmt .Errorf ("execute a command: %w" , err )
@@ -99,28 +93,12 @@ func aquaI(ctx context.Context) error {
99
93
}
100
94
101
95
func createPkgFile (ctx context.Context , pkgName , pkgFilePath string ) error {
102
- outFile , err := os .Create (pkgFilePath )
103
- if err != nil {
104
- return fmt .Errorf ("create a file %s: %w" , pkgFilePath , err )
105
- }
106
- defer outFile .Close ()
107
- if _ , err := outFile .WriteString ("packages:\n " ); err != nil {
108
- return fmt .Errorf ("write a string to file %s: %w" , pkgFilePath , err )
109
- }
110
- buf := & bytes.Buffer {}
111
- fmt .Fprintf (os .Stderr , "+ aqua -c aqua-all.yaml g %s >> %s\n " , pkgName , pkgFilePath )
112
- cmd := exec .CommandContext (ctx , "aqua" , "-c" , "aqua-all.yaml" , "g" , pkgName )
113
- cmd .Stdout = buf
96
+ fmt .Fprintf (os .Stderr , "+ aqua -c aqua-all.yaml g -o %s %s\n " , pkgFilePath , pkgName )
97
+ cmd := exec .CommandContext (ctx , "aqua" , "-c" , "aqua-all.yaml" , "g" , "-o" , pkgFilePath , pkgName )
98
+ cmd .Stdout = os .Stdout
114
99
cmd .Stderr = os .Stderr
115
100
if err := cmd .Run (); err != nil {
116
101
return fmt .Errorf ("execute a command: aqua g %s: %w" , pkgName , err )
117
102
}
118
- txt := ""
119
- for _ , line := range strings .Split (strings .TrimSpace (buf .String ()), "\n " ) {
120
- txt += fmt .Sprintf (" %s\n " , line )
121
- }
122
- if _ , err := outFile .WriteString (txt ); err != nil {
123
- return fmt .Errorf ("write a string to file %s: %w" , pkgFilePath , err )
124
- }
125
103
return nil
126
104
}
0 commit comments