sort : port over full code, fix flag value iteration skipping in parseArgs
This commit is contained in:
parent
d404b3d096
commit
ba46937c3c
2 changed files with 110 additions and 2 deletions
29
pipe/pipe.go
Normal file
29
pipe/pipe.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package pipe
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const Newline string = "\n"
|
||||
|
||||
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), Newline)
|
||||
return strings.Split(s, Newline), nil
|
||||
}
|
||||
Loading…
Reference in a new issue