bb/tool/read/main.go

33 lines
479 B
Go
Raw Normal View History

2022-06-17 01:53:25 +03:00
package read
/* Plan9 read or something to read into variables. */
import(
"os"
"bufio"
"fmt"
2024-01-05 03:22:55 +03:00
"vultras.su/core/cli/mtool"
2022-06-17 01:53:25 +03:00
)
var(
nLines int
)
2023-03-24 16:54:51 +03:00
func Run(flagSet *mtool.Flags) {
2022-06-17 01:53:25 +03:00
flagSet.IntVar(&nLines, "n", 1, "amount of lines")
2023-03-24 16:54:51 +03:00
flagSet.Parse()
//args := flagSet.Args()
2022-06-17 01:53:25 +03:00
if nLines <= 0 {
flagSet.Usage()
}
rd := bufio.NewReader(os.Stdin)
for nLines != 0 {
line, err := rd.ReadString('\n')
if err != nil {
os.Exit(0)
}
fmt.Print(line)
nLines -= 1
}
}