Added simplified "sort" commabe implementation.

This commit is contained in:
jienfak 2020-02-26 20:04:11 +05:00
parent 62a40b80e9
commit 010d8f8f4e
2 changed files with 39 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import(
"github.com/jienfak/goblin/mkdir"
"github.com/jienfak/goblin/gtrue"
"github.com/jienfak/goblin/gfalse"
"github.com/jienfak/goblin/sort"
)
func main() {
@ -24,6 +25,7 @@ func main() {
"echo" : echo.Run,
"true" : gtrue.Run,
"false" : gfalse.Run,
"sort" : sort.Run,
}
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {

37
sort/sort.go Normal file
View file

@ -0,0 +1,37 @@
package sort
import (
"bufio"
"fmt"
"os"
"sort"
"io"
"flag"
)
func readLines() []string {
r := bufio.NewReader(os.Stdin)
a := make([]string, 0)
for {
l, e := r.ReadString('\n')
if e==io.EOF {
break
}
a = append(a, l)
}
return a
}
func Run(args []string) int {
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
flagSet.Parse(args[1:])
status := 0
lines := readLines()
sort.Strings(lines)
for _, l := range lines {
fmt.Print(l)
}
return status
}