Use gomtool instead hand done tree runner.
This commit is contained in:
parent
c7e44cfabb
commit
c9b1fbd40e
30 changed files with 93 additions and 141 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
exe/
|
|
@ -1,5 +0,0 @@
|
|||
package gfalse
|
||||
|
||||
func Run(args []string) int {
|
||||
return 1
|
||||
}
|
5
go.mod
5
go.mod
|
@ -1,4 +1,5 @@
|
|||
module goblin
|
||||
module github.com/k1574/goblin
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require github.com/k1574/gomtool v0.0.0-20220616060224-023d1559d777 // indirect
|
||||
|
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
github.com/k1574/gomtool v0.0.0-20220616060224-023d1559d777 h1:r4Wm40GwE7GNC3VbIwVGtD8dPDw5NDsI5xlpcYF5Nv4=
|
||||
github.com/k1574/gomtool v0.0.0-20220616060224-023d1559d777/go.mod h1:XT2+xWYiSEE6eX/nBgE6UnfIrBfijwPfv4fNJSVD+SA=
|
|
@ -1,5 +0,0 @@
|
|||
package gtrue
|
||||
|
||||
func Run(args []string) int {
|
||||
return 0
|
||||
}
|
3
install
3
install
|
@ -1,3 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
go install
|
||||
exec mk install
|
||||
|
||||
|
|
46
m/cmd/goblin/main.go
Normal file
46
m/cmd/goblin/main.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
"github.com/k1574/gomtool/m/multitool"
|
||||
"github.com/k1574/goblin/m/sep/cat"
|
||||
"github.com/k1574/goblin/m/sep/echo"
|
||||
"github.com/k1574/goblin/m/sep/mkdir"
|
||||
"github.com/k1574/goblin/m/sep/gtrue"
|
||||
"github.com/k1574/goblin/m/sep/gfalse"
|
||||
"github.com/k1574/goblin/m/sep/sort"
|
||||
"github.com/k1574/goblin/m/sep/tac"
|
||||
"github.com/k1574/goblin/m/sep/ls"
|
||||
"github.com/k1574/goblin/m/sep/yes"
|
||||
"github.com/k1574/goblin/m/sep/date"
|
||||
"github.com/k1574/goblin/m/sep/uniq"
|
||||
"github.com/k1574/goblin/m/sep/quote"
|
||||
"github.com/k1574/goblin/m/sep/urlprs"
|
||||
"github.com/k1574/goblin/m/sep/noext"
|
||||
"github.com/k1574/goblin/m/sep/mergelbl"
|
||||
"github.com/k1574/goblin/m/sep/basename"
|
||||
"github.com/k1574/goblin/m/sep/ec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tools := multitool.Tools {
|
||||
"basename" : basename.Run,
|
||||
"cat": cat.Run,
|
||||
"mkdir" : mkdir.Run,
|
||||
"echo" : echo.Run,
|
||||
"true" : gtrue.Run,
|
||||
"false" : gfalse.Run,
|
||||
"sort" : sort.Run,
|
||||
"tac" : tac.Run,
|
||||
"ls" : ls.Run,
|
||||
"yes" : yes.Run,
|
||||
"date" : date.Run,
|
||||
"uniq" : uniq.Run,
|
||||
"quote" : quote.Run,
|
||||
"urlprs" : urlprs.Run,
|
||||
"noext" : noext.Run,
|
||||
"mergelbl" : mergelbl.Run,
|
||||
"ec" : ec.Run,
|
||||
}
|
||||
|
||||
multitool.Main("goblin", tools)
|
||||
}
|
|
@ -18,8 +18,7 @@ func Base(p string) string {
|
|||
return path.Base(p)
|
||||
}
|
||||
|
||||
func Run(argv []string) int {
|
||||
status := 0
|
||||
func Run(argv []string) {
|
||||
arg0 = argv[0]
|
||||
args = argv[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -38,5 +37,4 @@ func Run(argv []string) int {
|
|||
}
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
|
@ -37,8 +37,7 @@ func fcat(f *os.File) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
status := 0
|
||||
func Run(args []string) {
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -54,11 +53,9 @@ func Run(args []string) int {
|
|||
e := Cat(p)
|
||||
if e != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fcat(os.Stdin)
|
||||
}
|
||||
return status
|
||||
}
|
|
@ -7,8 +7,7 @@ import(
|
|||
"time"
|
||||
)
|
||||
|
||||
func Run(args []string) int {
|
||||
status := 0
|
||||
func Run(args []string) {
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -27,5 +26,4 @@ func Run(args []string) int {
|
|||
|
||||
fmt.Println(date)
|
||||
|
||||
return status
|
||||
}
|
|
@ -31,7 +31,7 @@ handleEscChar(rd *bufio.Reader) error {
|
|||
}
|
||||
|
||||
func
|
||||
Run(args []string) int {
|
||||
Run(args []string) {
|
||||
rd := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
r, _, e := rd.ReadRune()
|
||||
|
@ -48,5 +48,4 @@ Run(args []string) int {
|
|||
fmt.Print(string(r))
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
|
@ -11,7 +11,7 @@ var(
|
|||
eol = "\n"
|
||||
)
|
||||
|
||||
func Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
var nflag bool
|
||||
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
|
||||
flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.")
|
||||
|
@ -27,5 +27,4 @@ func Run(args []string) int {
|
|||
fmt.Print(eol)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
4
m/sep/gfalse/false.go
Normal file
4
m/sep/gfalse/false.go
Normal file
|
@ -0,0 +1,4 @@
|
|||
package gfalse
|
||||
|
||||
func Run(args []string) {
|
||||
}
|
5
m/sep/gtrue/true.go
Normal file
5
m/sep/gtrue/true.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
package gtrue
|
||||
|
||||
func Run(args []string) {
|
||||
}
|
||||
|
|
@ -126,8 +126,7 @@ ls(p string, fold int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Run(argv []string) int {
|
||||
status := 0
|
||||
func Run(argv []string) {
|
||||
arg0 = argv[0]
|
||||
args = argv[1:]
|
||||
flagSet = flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -139,18 +138,17 @@ func Run(argv []string) int {
|
|||
|
||||
if foldLvl<0 {
|
||||
flagSet.Usage()
|
||||
return 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if foldLvl==0 && len(args)==0 {
|
||||
flagSet.Usage()
|
||||
return 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
foldLvl -= 1
|
||||
if l, e := ReadDir(".") ; e != nil {
|
||||
status = 1
|
||||
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
|
||||
} else {
|
||||
for _, f := range l {
|
||||
|
@ -163,7 +161,6 @@ func Run(argv []string) int {
|
|||
if isDir && foldLvl>0 {
|
||||
e := ls(f.Name(), foldLvl)
|
||||
if e!=nil {
|
||||
status = 1
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"%s: %s\n",
|
||||
arg0, e)
|
||||
|
@ -175,11 +172,9 @@ func Run(argv []string) int {
|
|||
for _, p := range args {
|
||||
e := ls(p, foldLvl)
|
||||
if e != nil {
|
||||
status = 1
|
||||
fmt.Fprintf(os.Stderr, "%s: %s\n", arg0, e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return status
|
||||
}
|
|
@ -8,8 +8,7 @@ import(
|
|||
"log"
|
||||
)
|
||||
|
||||
func
|
||||
Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
var(
|
||||
e error
|
||||
buf string
|
||||
|
@ -17,7 +16,6 @@ Run(args []string) int {
|
|||
rsep := '\n'
|
||||
wsep := "\n"
|
||||
//del := ""
|
||||
status := 0
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -46,12 +44,11 @@ Run(args []string) int {
|
|||
for _, r := range rds{
|
||||
buf, e = r.ReadString(byte(rsep))
|
||||
if e!=nil {
|
||||
return 0
|
||||
os.Exit(1)
|
||||
}
|
||||
s += buf[:len(buf)-1]
|
||||
}
|
||||
fmt.Printf("%s%s", s, wsep)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
|
@ -6,8 +6,7 @@ import(
|
|||
"flag"
|
||||
)
|
||||
|
||||
func Run(args []string) int {
|
||||
status := 0
|
||||
func Run(args []string) {
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
var (
|
||||
|
@ -36,8 +35,6 @@ func Run(args []string) int {
|
|||
}
|
||||
if e != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
return status
|
||||
}
|
|
@ -25,8 +25,7 @@ func NoExt(p string) string {
|
|||
return p[:i]
|
||||
}
|
||||
|
||||
func Run(argv []string) int {
|
||||
status := 0
|
||||
func Run(argv []string) {
|
||||
arg0 = argv[0]
|
||||
args = argv[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -37,5 +36,4 @@ func Run(argv []string) int {
|
|||
flagSet.Parse(args)
|
||||
args = flagSet.Args()
|
||||
fmt.Printf("%s", NoExt(args[0]))
|
||||
return status
|
||||
}
|
|
@ -19,8 +19,7 @@ func HasWhiteSpace(s string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
status := 0
|
||||
func Run(args []string) {
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -47,5 +46,4 @@ func Run(args []string) int {
|
|||
fmt.Println(l)
|
||||
}
|
||||
}
|
||||
return status
|
||||
}
|
|
@ -5,13 +5,12 @@ import (
|
|||
"os"
|
||||
"sort"
|
||||
"flag"
|
||||
"goblin/input"
|
||||
"github.com/k1574/goblin/m/gen/input"
|
||||
)
|
||||
|
||||
func Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
|
||||
flagSet.Parse(args[1:])
|
||||
status := 0
|
||||
|
||||
lines, _ := input.ReadAllLines(os.Stdin)
|
||||
sort.Strings(lines)
|
||||
|
@ -19,5 +18,4 @@ func Run(args []string) int {
|
|||
fmt.Print(l)
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
|
@ -47,8 +47,7 @@ func ftac(f *os.File) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
status := 0
|
||||
func Run(args []string) {
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -63,11 +62,9 @@ func Run(args []string) int {
|
|||
e := tac(p)
|
||||
if e != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e)
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ftac(os.Stdin)
|
||||
}
|
||||
return status
|
||||
}
|
|
@ -9,11 +9,10 @@ import(
|
|||
"io"
|
||||
)
|
||||
|
||||
func Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
var(
|
||||
Uflag bool
|
||||
)
|
||||
status := 0
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -41,5 +40,4 @@ func Run(args []string) int {
|
|||
}
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package urlprs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
|
@ -15,14 +16,14 @@ func printNil(s string) {
|
|||
fmt.Println(nilStr)
|
||||
}
|
||||
}
|
||||
func Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
nilStr = "_"
|
||||
|
||||
s := args[1]
|
||||
|
||||
u, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
printNil(u.Scheme)
|
||||
|
@ -44,6 +45,5 @@ func Run(args []string) int {
|
|||
m, _ := url.ParseQuery(u.RawQuery)
|
||||
fmt.Println(m)
|
||||
fmt.Println(m["k"][0])*/
|
||||
return 0
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ import(
|
|||
"fmt"
|
||||
"flag"
|
||||
"strings"
|
||||
"goblin/input"
|
||||
"github.com/k1574/goblin/m/gen/input"
|
||||
)
|
||||
var(
|
||||
nArg int
|
||||
|
@ -24,13 +24,12 @@ func yes(s string){
|
|||
}
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
func Run(args []string) {
|
||||
var(
|
||||
stdinFlag bool
|
||||
nFlag bool
|
||||
s string
|
||||
)
|
||||
status := 0
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
|
@ -61,5 +60,4 @@ func Run(args []string) int {
|
|||
|
||||
yes(s)
|
||||
|
||||
return status
|
||||
}
|
73
main.go
73
main.go
|
@ -1,73 +0,0 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"goblin/cat"
|
||||
"goblin/echo"
|
||||
"goblin/mkdir"
|
||||
"goblin/gtrue"
|
||||
"goblin/gfalse"
|
||||
"goblin/sort"
|
||||
"goblin/tac"
|
||||
"goblin/ls"
|
||||
"goblin/yes"
|
||||
"goblin/date"
|
||||
"goblin/uniq"
|
||||
"goblin/quote"
|
||||
"goblin/urlprs"
|
||||
"goblin/noext"
|
||||
"goblin/mergelbl"
|
||||
"goblin/basename"
|
||||
"goblin/ec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var(
|
||||
utilName string
|
||||
args []string
|
||||
)
|
||||
|
||||
|
||||
utilsMap := map[string] interface{} {
|
||||
"basename" : basename.Run,
|
||||
"cat": cat.Run,
|
||||
"mkdir" : mkdir.Run,
|
||||
"echo" : echo.Run,
|
||||
"true" : gtrue.Run,
|
||||
"false" : gfalse.Run,
|
||||
"sort" : sort.Run,
|
||||
"tac" : tac.Run,
|
||||
"ls" : ls.Run,
|
||||
"yes" : yes.Run,
|
||||
"date" : date.Run,
|
||||
"uniq" : uniq.Run,
|
||||
"quote" : quote.Run,
|
||||
"urlprs" : urlprs.Run,
|
||||
"noext" : noext.Run,
|
||||
"mergelbl" : mergelbl.Run,
|
||||
"ec" : ec.Run,
|
||||
}
|
||||
|
||||
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {
|
||||
utilName = binBase
|
||||
args = os.Args[:]
|
||||
} else {
|
||||
if len(os.Args)<2 {
|
||||
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 {
|
||||
fmt.Printf("%s: No such uitl as '%s'.\n", os.Args[0], utilName )
|
||||
os.Exit(1)
|
||||
}
|
||||
status := utilsMap[utilName].(func([]string) int )(args)
|
||||
os.Exit(status)
|
||||
}
|
3
mkconfig
Normal file
3
mkconfig
Normal file
|
@ -0,0 +1,3 @@
|
|||
<$MKINCDIR/config
|
||||
CC = cc
|
||||
|
3
mkfile
Normal file
3
mkfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
<mkconfig
|
||||
<$MKINCDIR/gobuild
|
||||
|
2
readme
2
readme
|
@ -1,5 +1,7 @@
|
|||
# goblin
|
||||
|
||||
GO Base utils LINked.
|
||||
|
||||
Base utils without exceed (like "cat -v") options
|
||||
and with additional options I needed in my scripts.
|
||||
|
||||
|
|
BIN
urlprs/urlprs
BIN
urlprs/urlprs
Binary file not shown.
Loading…
Reference in a new issue