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

feat: support run entry from stdin #136

Merged
merged 1 commit into from
Aug 15, 2024
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
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
Loading