read: basic implementation.
This commit is contained in:
parent
c9b1fbd40e
commit
6628b533c3
2 changed files with 42 additions and 0 deletions
|
@ -19,6 +19,7 @@ import(
|
||||||
"github.com/k1574/goblin/m/sep/mergelbl"
|
"github.com/k1574/goblin/m/sep/mergelbl"
|
||||||
"github.com/k1574/goblin/m/sep/basename"
|
"github.com/k1574/goblin/m/sep/basename"
|
||||||
"github.com/k1574/goblin/m/sep/ec"
|
"github.com/k1574/goblin/m/sep/ec"
|
||||||
|
"github.com/k1574/goblin/m/sep/read"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -40,6 +41,7 @@ func main() {
|
||||||
"noext" : noext.Run,
|
"noext" : noext.Run,
|
||||||
"mergelbl" : mergelbl.Run,
|
"mergelbl" : mergelbl.Run,
|
||||||
"ec" : ec.Run,
|
"ec" : ec.Run,
|
||||||
|
"read" : read.Run,
|
||||||
}
|
}
|
||||||
|
|
||||||
multitool.Main("goblin", tools)
|
multitool.Main("goblin", tools)
|
||||||
|
|
40
m/sep/read/main.go
Normal file
40
m/sep/read/main.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package read
|
||||||
|
/* Plan9 read or something to read into variables. */
|
||||||
|
import(
|
||||||
|
"os"
|
||||||
|
"bufio"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
nLines int
|
||||||
|
)
|
||||||
|
|
||||||
|
func Run(args []string) {
|
||||||
|
arg0 := args[0]
|
||||||
|
args = args[1:]
|
||||||
|
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||||
|
flagSet.IntVar(&nLines, "n", 1, "amount of lines")
|
||||||
|
flagSet.Usage = func() {
|
||||||
|
fmt.Fprintf(os.Stderr, "usage: %s [options] [files]\n", arg0)
|
||||||
|
flagSet.PrintDefaults()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
flagSet.Parse(args)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue