Skip to content
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

Copy generator.yaml to apis/version directory #109

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion cmd/ack-generate/command/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
generate "github.com/aws-controllers-k8s/code-generator/pkg/generate"
ackgenerate "github.com/aws-controllers-k8s/code-generator/pkg/generate/ack"
"github.com/aws-controllers-k8s/code-generator/pkg/model"
"github.com/aws-controllers-k8s/code-generator/pkg/util"
)

type contentType int
Expand Down Expand Up @@ -65,7 +66,19 @@ func saveGeneratedMetadata(cmd *cobra.Command, args []string) error {
optAWSSDKGoVersion,
optGeneratorConfigPath,
)
return err
if err != nil {
return fmt.Errorf("cannot create generation metadata file: %v", err)
}

copyDest := filepath.Join(
optOutputPath, "apis", optGenVersion, "generator.yaml",
)
err = util.CopyFile(optGeneratorConfigPath, copyDest)
if err != nil {
return fmt.Errorf("cannot copy generator configuration file: %v", err)
}

return nil
}

// generateAPIs generates the Go files for each resource in the AWS service
Expand Down
32 changes: 31 additions & 1 deletion pkg/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,40 @@

package util

import "os"
import (
"io"
"os"
)

// FileExists returns True if the supplied file path exists, false otherwise
func FileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

// CopyFile copies a file from a source path to a destination path.
func CopyFile(src, dest string) error {
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()

destFile, err := os.Create(dest)
if err != nil {
return err
}
defer destFile.Close()

_, err = io.Copy(destFile, srcFile)
if err != nil {
return err
}

err = destFile.Sync()
if err != nil {
return err
}

return nil
}