Skip to content

Commit eee49d5

Browse files
feat: use aqua g's -o option
1 parent 5660291 commit eee49d5

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

pkg/scaffold/api.go

+6-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scaffold
22

33
import (
4-
"bytes"
54
"context"
65
"errors"
76
"fmt"
@@ -70,15 +69,10 @@ func aquaGR(ctx context.Context, pkgName, rgFilePath string) error {
7069
}
7170

7271
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)
8074
cmd.Stdin = os.Stdin
81-
cmd.Stdout = outFile
75+
cmd.Stdout = os.Stdout
8276
cmd.Stderr = os.Stderr
8377
if err := cmd.Run(); err != nil {
8478
return fmt.Errorf("execute a command: %w", err)
@@ -99,28 +93,12 @@ func aquaI(ctx context.Context) error {
9993
}
10094

10195
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
11499
cmd.Stderr = os.Stderr
115100
if err := cmd.Run(); err != nil {
116101
return fmt.Errorf("execute a command: aqua g %s: %w", pkgName, err)
117102
}
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-
}
125103
return nil
126104
}

0 commit comments

Comments
 (0)