Skip to content

Commit 11d8540

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

File tree

1 file changed

+7
-32
lines changed

1 file changed

+7
-32
lines changed

pkg/scaffold/api.go

+7-32
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"
@@ -14,10 +13,7 @@ import (
1413
"github.com/aquaproj/registry-tool/pkg/initcmd"
1514
)
1615

17-
const (
18-
dirPermission os.FileMode = 0o775
19-
filePermission os.FileMode = 0o644
20-
)
16+
const dirPermission os.FileMode = 0o775
2117

2218
func Scaffold(ctx context.Context, pkgNames ...string) error {
2319
if len(pkgNames) != 1 {
@@ -70,15 +66,10 @@ func aquaGR(ctx context.Context, pkgName, rgFilePath string) error {
7066
}
7167

7268
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)
69+
fmt.Fprintf(os.Stderr, "+ aqua g -o aqua-loca.yaml %s\n", pkgName)
70+
cmd := exec.CommandContext(ctx, "aqua", "g", "-o", "aqua-local.yaml", pkgName)
8071
cmd.Stdin = os.Stdin
81-
cmd.Stdout = outFile
72+
cmd.Stdout = os.Stdout
8273
cmd.Stderr = os.Stderr
8374
if err := cmd.Run(); err != nil {
8475
return fmt.Errorf("execute a command: %w", err)
@@ -99,28 +90,12 @@ func aquaI(ctx context.Context) error {
9990
}
10091

10192
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
93+
fmt.Fprintf(os.Stderr, "+ aqua -c aqua-all.yaml g -o %s %s\n", pkgFilePath, pkgName)
94+
cmd := exec.CommandContext(ctx, "aqua", "-c", "aqua-all.yaml", "g", "-o", pkgFilePath, pkgName)
95+
cmd.Stdout = os.Stdout
11496
cmd.Stderr = os.Stderr
11597
if err := cmd.Run(); err != nil {
11698
return fmt.Errorf("execute a command: aqua g %s: %w", pkgName, err)
11799
}
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-
}
125100
return nil
126101
}

0 commit comments

Comments
 (0)