2019-10-30 02:54:45 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import(
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
2020-05-27 08:09:07 +03:00
|
|
|
"github.com/k1574/goblin/cat"
|
|
|
|
"github.com/k1574/goblin/echo"
|
|
|
|
"github.com/k1574/goblin/mkdir"
|
|
|
|
"github.com/k1574/goblin/gtrue"
|
|
|
|
"github.com/k1574/goblin/gfalse"
|
|
|
|
"github.com/k1574/goblin/sort"
|
|
|
|
"github.com/k1574/goblin/tac"
|
|
|
|
"github.com/k1574/goblin/ls"
|
|
|
|
"github.com/k1574/goblin/yes"
|
|
|
|
"github.com/k1574/goblin/date"
|
|
|
|
"github.com/k1574/goblin/uniq"
|
2020-06-07 22:51:39 +03:00
|
|
|
"github.com/k1574/goblin/quote"
|
2020-10-19 03:07:41 +03:00
|
|
|
"github.com/k1574/goblin/urlprs"
|
2021-03-08 02:35:25 +03:00
|
|
|
"github.com/k1574/goblin/noext"
|
2019-10-30 02:54:45 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var(
|
|
|
|
utilName string
|
|
|
|
args []string
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
utilsMap := map[string] interface{} {
|
|
|
|
"cat": cat.Run,
|
|
|
|
"mkdir" : mkdir.Run,
|
|
|
|
"echo" : echo.Run,
|
2019-11-08 02:00:23 +03:00
|
|
|
"true" : gtrue.Run,
|
|
|
|
"false" : gfalse.Run,
|
2020-02-26 18:04:11 +03:00
|
|
|
"sort" : sort.Run,
|
2020-02-27 06:37:41 +03:00
|
|
|
"tac" : tac.Run,
|
2020-03-08 03:24:41 +03:00
|
|
|
"ls" : ls.Run,
|
2020-03-14 01:44:50 +03:00
|
|
|
"yes" : yes.Run,
|
2020-05-05 07:52:35 +03:00
|
|
|
"date" : date.Run,
|
2020-05-25 02:23:16 +03:00
|
|
|
"uniq" : uniq.Run,
|
2020-06-07 22:51:39 +03:00
|
|
|
"quote" : quote.Run,
|
2020-10-19 03:07:41 +03:00
|
|
|
"urlprs" : urlprs.Run,
|
2021-03-08 02:35:25 +03:00
|
|
|
"noext" : noext.Run,
|
2019-10-30 02:54:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {
|
|
|
|
utilName = binBase
|
|
|
|
args = os.Args[:]
|
|
|
|
} else {
|
2019-10-30 03:01:12 +03:00
|
|
|
if len(os.Args)<2 {
|
2019-10-30 02:54:45 +03:00
|
|
|
for k, _ := range utilsMap {
|
|
|
|
fmt.Printf("%s\n", k)
|
|
|
|
}
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
utilName = os.Args[1]
|
|
|
|
args = os.Args[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := utilsMap[utilName] ; !ok {
|
2019-10-30 03:04:44 +03:00
|
|
|
fmt.Printf("%s: No such uitl as '%s'.\n", os.Args[0], utilName )
|
2019-10-30 02:54:45 +03:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
status := utilsMap[utilName].(func([]string) int )(args)
|
|
|
|
os.Exit(status)
|
2019-11-08 02:00:23 +03:00
|
|
|
}
|