From ec22effb45ae133c73c6816ed913bf87a0551f1e Mon Sep 17 00:00:00 2001 From: peefy Date: Thu, 15 Aug 2024 20:28:31 +0800 Subject: [PATCH] feat: support run entry from stdin Signed-off-by: peefy --- VERSION | 2 +- pkg/fs/util.go | 12 ++++++++++++ pkg/options/run.go | 18 +++++++++++++++++- pkg/version/version.go | 4 ++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 4b32fcf..805bf13 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.10.0-beta.1 \ No newline at end of file +0.10.0-beta.2 \ No newline at end of file diff --git a/pkg/fs/util.go b/pkg/fs/util.go index 8aecbff..bdd4fc7 100644 --- a/pkg/fs/util.go +++ b/pkg/fs/util.go @@ -7,6 +7,18 @@ import ( "path/filepath" ) +func GenTempFileFromStdin() (string, error) { + tempFile, err := os.CreateTemp("", "stdin") + if err != nil { + return "", err + } + _, err = io.Copy(tempFile, os.Stdin) + if err != nil { + return "", err + } + return tempFile.Name(), nil +} + func GetAllFilesInFolder(folderPath string, recursive bool) ([]string, error) { var fileList []string diff --git a/pkg/options/run.go b/pkg/options/run.go index e6a66dc..5976257 100644 --- a/pkg/options/run.go +++ b/pkg/options/run.go @@ -98,7 +98,7 @@ func (o *RunOptions) Run() error { if o.Quiet { cli.SetLogWriter(nil) } - // acquire the lock of the package cache. + // Acquire the lock of the package cache. err = cli.AcquirePackageCacheLock() if err != nil { return err @@ -110,6 +110,18 @@ func (o *RunOptions) Run() error { err = releaseErr } }() + // Generate temp entries from os.Stdin + tempEntries := []string{} + for i, entry := range o.Entries { + if entry == "-" { + entry, err := fs.GenTempFileFromStdin() + if err != nil { + return err + } + tempEntries = append(tempEntries, entry) + o.Entries[i] = entry + } + } result, err = cli.Run( client.WithRunSourceUrls(o.Entries), client.WithSettingFiles(o.Settings), @@ -133,6 +145,10 @@ func (o *RunOptions) Run() error { } return err } + // Remove temp entries + for _, entry := range tempEntries { + _ = os.Remove(entry) + } return o.writeResult(result) } diff --git a/pkg/version/version.go b/pkg/version/version.go index 3772c71..9cfdf46 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -32,9 +32,9 @@ func getVersion(version string) string { } const ( - VersionTypeLatest = Version_0_10_0_beta1 + VersionTypeLatest = Version_0_10_0_beta2 - Version_0_10_0_beta1 VersionType = "0.10.0-beta.1" + Version_0_10_0_beta2 VersionType = "0.10.0-beta.2" Version_0_9_8 VersionType = "0.9.8" Version_0_9_7 VersionType = "0.9.7"