Skip to content

Commit

Permalink
feat: support run entry from stdin
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Aug 15, 2024
1 parent e8cea33 commit ec22eff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0-beta.1
0.10.0-beta.2
12 changes: 12 additions & 0 deletions pkg/fs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion pkg/options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand All @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ec22eff

Please sign in to comment.