tag : pipe stdin
This commit is contained in:
parent
f3fed60ff8
commit
41b01c172b
1 changed files with 2 additions and 19 deletions
21
tag/tag.go
21
tag/tag.go
|
|
@ -16,6 +16,7 @@ import (
|
||||||
|
|
||||||
cmdpkg "github.com/brtholomy/um/go/cmd"
|
cmdpkg "github.com/brtholomy/um/go/cmd"
|
||||||
"github.com/brtholomy/um/go/flags"
|
"github.com/brtholomy/um/go/flags"
|
||||||
|
"github.com/brtholomy/um/go/pipe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// just so that copied calls into flags.Help don't have to be adjusted between files:
|
// just so that copied calls into flags.Help don't have to be adjusted between files:
|
||||||
|
|
@ -141,27 +142,9 @@ func (s Set) Intersect(t Set) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isStdinLoaded() bool {
|
|
||||||
stat, _ := os.Stdin.Stat()
|
|
||||||
return (stat.Mode() & os.ModeCharDevice) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetStdin() ([]string, error) {
|
|
||||||
if !isStdinLoaded() {
|
|
||||||
return nil, errors.New("stdin not loaded")
|
|
||||||
}
|
|
||||||
data, err := io.ReadAll(os.Stdin)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
// TODO: there's got to be a better way:
|
|
||||||
s, _ := strings.CutSuffix(string(data), "\n")
|
|
||||||
return strings.Split(s, "\n"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// reads files from stdin if present, otherwise from the glob pattern:
|
// reads files from stdin if present, otherwise from the glob pattern:
|
||||||
func Filelist(glob string) []string {
|
func Filelist(glob string) []string {
|
||||||
filelist, err := GetStdin()
|
filelist, err := pipe.GetStdin()
|
||||||
// otherwise get from the glob:
|
// otherwise get from the glob:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
filelist, err = filepath.Glob(glob)
|
filelist, err = filepath.Glob(glob)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue