Skip to content

feat: use aqua g's -o option #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 7 additions & 32 deletions pkg/scaffold/api.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package scaffold

import (
"bytes"
"context"
"errors"
"fmt"
Expand All @@ -14,10 +13,7 @@ import (
"github.com/aquaproj/registry-tool/pkg/initcmd"
)

const (
dirPermission os.FileMode = 0o775
filePermission os.FileMode = 0o644
)
const dirPermission os.FileMode = 0o775

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

func aquaG(ctx context.Context, pkgName string) error {
outFile, err := os.OpenFile("aqua-local.yaml", os.O_APPEND|os.O_CREATE|os.O_WRONLY, filePermission)
if err != nil {
return fmt.Errorf("open aqua-local.yaml: %w", err)
}
defer outFile.Close()
fmt.Fprintf(os.Stderr, "+ aqua g %s >> aqua-local.yaml\n", pkgName)
cmd := exec.CommandContext(ctx, "aqua", "g", pkgName)
fmt.Fprintf(os.Stderr, "+ aqua g -o aqua-loca.yaml %s\n", pkgName)
cmd := exec.CommandContext(ctx, "aqua", "g", "-o", "aqua-local.yaml", pkgName)
cmd.Stdin = os.Stdin
cmd.Stdout = outFile
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("execute a command: %w", err)
Expand All @@ -99,28 +90,12 @@ func aquaI(ctx context.Context) error {
}

func createPkgFile(ctx context.Context, pkgName, pkgFilePath string) error {
outFile, err := os.Create(pkgFilePath)
if err != nil {
return fmt.Errorf("create a file %s: %w", pkgFilePath, err)
}
defer outFile.Close()
if _, err := outFile.WriteString("packages:\n"); err != nil {
return fmt.Errorf("write a string to file %s: %w", pkgFilePath, err)
}
buf := &bytes.Buffer{}
fmt.Fprintf(os.Stderr, "+ aqua -c aqua-all.yaml g %s >> %s\n", pkgName, pkgFilePath)
cmd := exec.CommandContext(ctx, "aqua", "-c", "aqua-all.yaml", "g", pkgName)
cmd.Stdout = buf
fmt.Fprintf(os.Stderr, "+ aqua -c aqua-all.yaml g -o %s %s\n", pkgFilePath, pkgName)
cmd := exec.CommandContext(ctx, "aqua", "-c", "aqua-all.yaml", "g", "-o", pkgFilePath, pkgName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("execute a command: aqua g %s: %w", pkgName, err)
}
txt := ""
for _, line := range strings.Split(strings.TrimSpace(buf.String()), "\n") {
txt += fmt.Sprintf(" %s\n", line)
}
if _, err := outFile.WriteString(txt); err != nil {
return fmt.Errorf("write a string to file %s: %w", pkgFilePath, err)
}
return nil
}