mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-10-14 09:57:16 +00:00
Generalize to read filter from file or stdin.
This commit is contained in:
1 parent
a5d322252a
commit
005114839a
5 files changed
+55
-42
No files matched your search
+35
@@ -7,6 +7,9 @@ import (
|
||||
"os"
|
||||
"text/template"
|
||||
"time"
|
||||
"bufio"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/aptly-dev/aptly/aptly"
|
||||
"github.com/aptly-dev/aptly/deb"
|
||||
@@ -129,3 +132,35 @@ package environment to new version.`,
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Reads the content of a file. If the file is "-", reads from stdin.
|
||||
func getContent(filterarg string) (string, error) {
|
||||
var err error
|
||||
// Check if filterarg starts with '@'
|
||||
if strings.HasPrefix(filterarg, "@") {
|
||||
// Remove the '@' character from filterarg
|
||||
filterarg = strings.TrimPrefix(filterarg, "@")
|
||||
if filterarg == "-" {
|
||||
// If filterarg is "-", read from stdin
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Split(bufio.ScanLines)
|
||||
scanner.Buffer(make([]byte, 1024*1024), 1024*1024)
|
||||
var content strings.Builder
|
||||
for scanner.Scan() {
|
||||
content.WriteString(scanner.Text() + "\n")
|
||||
}
|
||||
err = scanner.Err()
|
||||
if err == nil {
|
||||
filterarg = content.String()
|
||||
}
|
||||
} else {
|
||||
// Read the file content into a byte slice
|
||||
var data []byte
|
||||
data, err = ioutil.ReadFile(filterarg)
|
||||
if err == nil {
|
||||
filterarg = string(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
return filterarg, err
|
||||
}
|
||||
Reference in new issue
Block a user