bb/tool/read/main.go
2024-01-04 17:13:03 +03:00

32 lines
482 B
Go

package read
/* Plan9 read or something to read into variables. */
import(
"os"
"bufio"
"fmt"
"github.com/vultras/cli/mtool"
)
var(
nLines int
)
func Run(flagSet *mtool.Flags) {
flagSet.IntVar(&nLines, "n", 1, "amount of lines")
flagSet.Parse()
//args := flagSet.Args()
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
}
}