diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..09c8b20 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +exe/ diff --git a/gfalse/false.go b/gfalse/false.go deleted file mode 100644 index 043fe8a..0000000 --- a/gfalse/false.go +++ /dev/null @@ -1,5 +0,0 @@ -package gfalse - -func Run(args []string) int { - return 1 -} \ No newline at end of file diff --git a/go.mod b/go.mod index c3dea66..b835919 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..47d9856 --- /dev/null +++ b/go.sum @@ -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= diff --git a/gtrue/true.go b/gtrue/true.go deleted file mode 100644 index 56a5308..0000000 --- a/gtrue/true.go +++ /dev/null @@ -1,5 +0,0 @@ -package gtrue - -func Run(args []string) int { - return 0 -} \ No newline at end of file diff --git a/install b/install index 78050c5..76644cd 100755 --- a/install +++ b/install @@ -1,3 +1,4 @@ #!/bin/sh -go install +exec mk install + diff --git a/m/cmd/goblin/main.go b/m/cmd/goblin/main.go new file mode 100644 index 0000000..56cc954 --- /dev/null +++ b/m/cmd/goblin/main.go @@ -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) +} diff --git a/input/read.go b/m/gen/input/read.go similarity index 100% rename from input/read.go rename to m/gen/input/read.go diff --git a/basename/run.go b/m/sep/basename/run.go similarity index 90% rename from basename/run.go rename to m/sep/basename/run.go index d93d267..4348286 100644 --- a/basename/run.go +++ b/m/sep/basename/run.go @@ -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 } diff --git a/cat/cat.go b/m/sep/cat/cat.go similarity index 92% rename from cat/cat.go rename to m/sep/cat/cat.go index 9519613..6c87253 100644 --- a/cat/cat.go +++ b/m/sep/cat/cat.go @@ -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 } diff --git a/date/date.go b/m/sep/date/date.go similarity index 86% rename from date/date.go rename to m/sep/date/date.go index a65f5dc..a3a5601 100644 --- a/date/date.go +++ b/m/sep/date/date.go @@ -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 } diff --git a/ec/run.go b/m/sep/ec/run.go similarity index 93% rename from ec/run.go rename to m/sep/ec/run.go index 5295453..802b39e 100644 --- a/ec/run.go +++ b/m/sep/ec/run.go @@ -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 } diff --git a/echo/echo.go b/m/sep/echo/echo.go similarity index 92% rename from echo/echo.go rename to m/sep/echo/echo.go index ea135cc..b8a3979 100644 --- a/echo/echo.go +++ b/m/sep/echo/echo.go @@ -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 } diff --git a/m/sep/gfalse/false.go b/m/sep/gfalse/false.go new file mode 100644 index 0000000..bf1069a --- /dev/null +++ b/m/sep/gfalse/false.go @@ -0,0 +1,4 @@ +package gfalse + +func Run(args []string) { +} diff --git a/m/sep/gtrue/true.go b/m/sep/gtrue/true.go new file mode 100644 index 0000000..5b7f30c --- /dev/null +++ b/m/sep/gtrue/true.go @@ -0,0 +1,5 @@ +package gtrue + +func Run(args []string) { +} + diff --git a/ls/ls.go b/m/sep/ls/ls.go similarity index 95% rename from ls/ls.go rename to m/sep/ls/ls.go index 998ec3c..fd6d79d 100644 --- a/ls/ls.go +++ b/m/sep/ls/ls.go @@ -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 } diff --git a/mergelbl/main.go b/m/sep/mergelbl/main.go similarity index 91% rename from mergelbl/main.go rename to m/sep/mergelbl/main.go index aeed434..b5d6508 100644 --- a/mergelbl/main.go +++ b/m/sep/mergelbl/main.go @@ -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 } diff --git a/mkdir/mkdir.go b/m/sep/mkdir/mkdir.go similarity index 91% rename from mkdir/mkdir.go rename to m/sep/mkdir/mkdir.go index 847f167..67c5458 100644 --- a/mkdir/mkdir.go +++ b/m/sep/mkdir/mkdir.go @@ -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 } diff --git a/noext/noext.go b/m/sep/noext/noext.go similarity index 91% rename from noext/noext.go rename to m/sep/noext/noext.go index 42aaf52..dd67104 100644 --- a/noext/noext.go +++ b/m/sep/noext/noext.go @@ -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 } diff --git a/quote/quote.go b/m/sep/quote/quote.go similarity index 92% rename from quote/quote.go rename to m/sep/quote/quote.go index 2ed19fe..6910eae 100644 --- a/quote/quote.go +++ b/m/sep/quote/quote.go @@ -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 } diff --git a/sort/sort.go b/m/sep/sort/sort.go similarity index 77% rename from sort/sort.go rename to m/sep/sort/sort.go index a78a6eb..1c2b862 100644 --- a/sort/sort.go +++ b/m/sep/sort/sort.go @@ -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 } diff --git a/tac/tac.go b/m/sep/tac/tac.go similarity index 93% rename from tac/tac.go rename to m/sep/tac/tac.go index a3b335a..2ca431d 100644 --- a/tac/tac.go +++ b/m/sep/tac/tac.go @@ -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 } diff --git a/uniq/uniq.go b/m/sep/uniq/uniq.go similarity index 92% rename from uniq/uniq.go rename to m/sep/uniq/uniq.go index 89b8b47..682f06f 100644 --- a/uniq/uniq.go +++ b/m/sep/uniq/uniq.go @@ -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 } diff --git a/urlprs/urlprs.go b/m/sep/urlprs/urlprs.go similarity index 92% rename from urlprs/urlprs.go rename to m/sep/urlprs/urlprs.go index 93cefb1..dbece0f 100644 --- a/urlprs/urlprs.go +++ b/m/sep/urlprs/urlprs.go @@ -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 } diff --git a/yes/yes.go b/m/sep/yes/yes.go similarity index 92% rename from yes/yes.go rename to m/sep/yes/yes.go index bbd2576..5ab47d4 100644 --- a/yes/yes.go +++ b/m/sep/yes/yes.go @@ -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 } diff --git a/main.go b/main.go deleted file mode 100644 index 07a6433..0000000 --- a/main.go +++ /dev/null @@ -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) -} diff --git a/mkconfig b/mkconfig new file mode 100644 index 0000000..2f8ccb0 --- /dev/null +++ b/mkconfig @@ -0,0 +1,3 @@ +<$MKINCDIR/config +CC = cc + diff --git a/mkfile b/mkfile new file mode 100644 index 0000000..0c5baf7 --- /dev/null +++ b/mkfile @@ -0,0 +1,3 @@ +