diff --git a/go.mod b/go.mod index e8dd8b0..8d5edd3 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/surdeus/goblin go 1.18 -require github.com/surdeus/gomtool v0.0.0-20230216120523-b00a31dd9887 // indirect +require github.com/surdeus/gomtool v0.0.0-20230324073313-c382bc403f8b // indirect diff --git a/go.sum b/go.sum index 17b2af0..c1da825 100644 --- a/go.sum +++ b/go.sum @@ -8,3 +8,9 @@ github.com/surdeus/gomtool v0.0.0-20221123071619-d67de6873631 h1:dSnG4J2jusYRVnR github.com/surdeus/gomtool v0.0.0-20221123071619-d67de6873631/go.mod h1:48d4QXOu0MwH0fbqseBInNdS6WiJ0+EzZU9K5sGu4uo= github.com/surdeus/gomtool v0.0.0-20230216120523-b00a31dd9887 h1:lKe6TayY2qB50RqPYrHBlHPeJPevNViM+UQn8/2jBxc= github.com/surdeus/gomtool v0.0.0-20230216120523-b00a31dd9887/go.mod h1:48d4QXOu0MwH0fbqseBInNdS6WiJ0+EzZU9K5sGu4uo= +github.com/surdeus/gomtool v0.0.0-20230324065513-d8d05cb8077d h1:COfpUMABa+RrsD05bOnXDx9FX+oaJ+dnKiLpqOODxl8= +github.com/surdeus/gomtool v0.0.0-20230324065513-d8d05cb8077d/go.mod h1:48d4QXOu0MwH0fbqseBInNdS6WiJ0+EzZU9K5sGu4uo= +github.com/surdeus/gomtool v0.0.0-20230324070550-2fb327b6a6a6 h1:aOXHUmhQS/mCo8r72dERsxAnYrlk/hP61BAyZ79MkDs= +github.com/surdeus/gomtool v0.0.0-20230324070550-2fb327b6a6a6/go.mod h1:48d4QXOu0MwH0fbqseBInNdS6WiJ0+EzZU9K5sGu4uo= +github.com/surdeus/gomtool v0.0.0-20230324073313-c382bc403f8b h1:9IJVeXxRDTPlp12DQ8M76ydoyDCUx6J4up5UM2DwIXQ= +github.com/surdeus/gomtool v0.0.0-20230324073313-c382bc403f8b/go.mod h1:48d4QXOu0MwH0fbqseBInNdS6WiJ0+EzZU9K5sGu4uo= diff --git a/src/cmd/goblin/main.go b/src/cmd/goblin/main.go index 9071aeb..ac874d0 100644 --- a/src/cmd/goblin/main.go +++ b/src/cmd/goblin/main.go @@ -30,48 +30,51 @@ import ( "github.com/surdeus/goblin/src/tool/wc" "github.com/surdeus/goblin/src/tool/whoami" "github.com/surdeus/goblin/src/tool/yes" - mtool "github.com/surdeus/gomtool/src/multitool" + "github.com/surdeus/gomtool/src/mtool" ) func main() { tools := mtool.Tools{ - "basename": mtool.Tool{basename.Run, "get base name of file path"}, - "cat": mtool.Tool{cat.Run, "print file data to the standard output"}, - "mkdir": mtool.Tool{mkdir.Run, "make new directory"}, - "echo": mtool.Tool{echo.Run, "print strings to the standard output"}, - "true": mtool.Tool{gtrue.Run, "exit with true status"}, - "false": mtool.Tool{gfalse.Run, "exit with false status"}, - "sort": mtool.Tool{sort.Run, "sort strings inputed from standard input"}, - "tac": mtool.Tool{tac.Run, "print strings from standard input in reversed order"}, - "ls": mtool.Tool{ls.Run, "list directory content"}, - "yes": mtool.Tool{yes.Run, "print string infinite/exact amount times"}, - "date": mtool.Tool{date.Run, "print current date"}, - "uniq": mtool.Tool{uniq.Run, "filter repeated strings"}, - "quote": mtool.Tool{quote.Run, "quote words containing space characters"}, - "urlprs": mtool.Tool{urlprs.Run, "parse URLs"}, - "noext": mtool.Tool{noext.Run, "print file path without extension"}, - "mergelbl": mtool.Tool{mergelbl.Run, "merge line by line"}, - "ec": mtool.Tool{ec.Run, "render escape sequences"}, - "read": mtool.Tool{read.Run, "read lines and exit"}, - "wc": mtool.Tool{wc.Run, "count words, bytes, runes etc"}, - "ftest": mtool.Tool{ftest.Run, "filter files by specified features"}, - "range": mtool.Tool{grange.Run, "too lazy"}, - "in": mtool.Tool{in.Run, "filter strings from stdin that aren not in arguments"}, - "useprog": mtool.Tool{useprog.Run, "print the name of the first existing program in arg list"}, - "path": mtool.Tool{path.Run, "print cross platform path based on cmd arguments"}, - "mk": mtool.Tool{mk.Run, "file dependency system, simpler make"}, - "awk": mtool.Tool{awk.Run, "simple scripting language for working with string templates"}, + "basename": mtool.Tool{basename.Run, "get base name of file path", ""}, + "cat": mtool.Tool{cat.Run, "print file data to the standard output", ""}, + "mkdir": mtool.Tool{mkdir.Run, "make new directory", ""}, + "echo": mtool.Tool{echo.Run, "print strings to the standard output", ""}, + "true": mtool.Tool{gtrue.Run, "exit with true status", ""}, + "false": mtool.Tool{gfalse.Run, "exit with false status", ""}, + "sort": mtool.Tool{sort.Run, "sort strings inputed from standard input", ""}, + "tac": mtool.Tool{tac.Run, "print strings from standard input in reversed order", ""}, + "ls": mtool.Tool{ls.Run, "list directory content", ""}, + "yes": mtool.Tool{yes.Run, "print string infinite/exact amount times", ""}, + "date": mtool.Tool{date.Run, "print current date", ""}, + "uniq": mtool.Tool{uniq.Run, "filter repeated strings", ""}, + "quote": mtool.Tool{quote.Run, "quote words containing space characters", ""}, + "urlprs": mtool.Tool{urlprs.Run, "parse URLs", ""}, + "noext": mtool.Tool{noext.Run, "print file path without extension", ""}, + "mergelbl": mtool.Tool{mergelbl.Run, "merge line by line", ""}, + "ec": mtool.Tool{ec.Run, "render escape sequences", ""}, + "read": mtool.Tool{read.Run, "read lines and exit", ""}, + "wc": mtool.Tool{wc.Run, "count words, bytes, runes etc", ""}, + "ftest": mtool.Tool{ftest.Run, "filter files by specified features", ""}, + "range": mtool.Tool{grange.Run, "too lazy", ""}, + "in": mtool.Tool{in.Run, "filter strings from stdin that aren not in arguments", ""}, + "useprog": mtool.Tool{useprog.Run, "print the name of the first existing program in arg list", ""}, + "path": mtool.Tool{path.Run, "print cross platform path based on cmd arguments", ""}, + "mk": mtool.Tool{mk.Run, "file dependency system, simpler make", ""}, + "awk": mtool.Tool{awk.Run, "simple scripting language for working with string templates", ""}, "paths": mtool.Tool{ paths.Run, "convert UNIX slash separated paths into the OS compatible ones", + "", }, "whoami": mtool.Tool{ whoami.Run, "print current user name", + "", }, "ln": mtool.Tool{ ln.Run, "link files", + "", }, } diff --git a/src/tool/basename/run.go b/src/tool/basename/run.go index 4348286..f6b0bbb 100644 --- a/src/tool/basename/run.go +++ b/src/tool/basename/run.go @@ -3,9 +3,8 @@ package basename import( "fmt" - "flag" - "os" "path" + "github.com/surdeus/gomtool/src/mtool" ) var( @@ -18,16 +17,9 @@ func Base(p string) string { return path.Base(p) } -func Run(argv []string) { - arg0 = argv[0] - args = argv[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "usage: %s [files]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() +func Run(flags *mtool.Flags) { + flags.Parse() + args := flags.Args() lasti := len(args) - 1 for i, v := range args { diff --git a/src/tool/cat/cat.go b/src/tool/cat/cat.go index 6c87253..eb525b9 100644 --- a/src/tool/cat/cat.go +++ b/src/tool/cat/cat.go @@ -3,8 +3,8 @@ package cat import( "os" "io" - "flag" "fmt" + "github.com/surdeus/gomtool/src/mtool" ) var( @@ -37,22 +37,15 @@ func fcat(f *os.File) error { return nil } -func Run(args []string) { - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.IntVar(&blockSize, "bs", 512, "block size") - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "usage: %s [options] [files]\n", arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() +func Run(flags *mtool.Flags) { + flags.IntVar(&blockSize, "bs", 512, "block size") + flags.Parse() + args := flags.Args() if len(args)>0 { for _, p := range args { e := Cat(p) if e != nil { - fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) + fmt.Fprintf(os.Stderr, "%s.\n", e) } } } else { diff --git a/src/tool/date/date.go b/src/tool/date/date.go index a3a5601..4c8b649 100644 --- a/src/tool/date/date.go +++ b/src/tool/date/date.go @@ -1,25 +1,17 @@ package date import( - "os" - "flag" "fmt" "time" + "github.com/surdeus/gomtool/src/mtool" ) -func Run(args []string) { - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) +func Run(flagSet *mtool.Flags) { + flagSet.Parse() + args := flagSet.Args() - if len(flagSet.Args())>0 { + if len(args) > 0 { flagSet.Usage() - os.Exit(1) } date := time.Now() diff --git a/src/tool/ec/run.go b/src/tool/ec/run.go index 802b39e..38f869d 100644 --- a/src/tool/ec/run.go +++ b/src/tool/ec/run.go @@ -6,6 +6,7 @@ import( "os" "bufio" "log" + "github.com/surdeus/gomtool/src/mtool" ) const( @@ -31,7 +32,7 @@ handleEscChar(rd *bufio.Reader) error { } func -Run(args []string) { +Run(flags *mtool.Flags) { rd := bufio.NewReader(os.Stdin) for { r, _, e := rd.ReadRune() diff --git a/src/tool/echo/echo.go b/src/tool/echo/echo.go index b8a3979..5bf7704 100644 --- a/src/tool/echo/echo.go +++ b/src/tool/echo/echo.go @@ -3,7 +3,7 @@ package echo import ( "fmt" - "flag" + "github.com/surdeus/gomtool/src/mtool" ) var( @@ -11,13 +11,15 @@ var( eol = "\n" ) -func Run(args []string) { +func Run(flagSet *mtool.Flags) { var nflag bool - flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) + flagSet.BoolVar(&nflag, "n", false, "Do not print new line character.") flagSet.StringVar(&del, "d", " ", "Delimiter of arguments") - flagSet.Parse(args[1:]) - args = flagSet.Args() + + flagSet.Parse() + args := flagSet.Args() + l := len(args) - 1 for i, s := range args { fmt.Print(s) diff --git a/src/tool/gfalse/false.go b/src/tool/gfalse/false.go index bf1069a..ba9d279 100644 --- a/src/tool/gfalse/false.go +++ b/src/tool/gfalse/false.go @@ -1,4 +1,10 @@ package gfalse -func Run(args []string) { +import( + "os" + "github.com/surdeus/gomtool/src/mtool" +) + +func Run(flags *mtool.Flags) { + os.Exit(1) } diff --git a/src/tool/gtrue/true.go b/src/tool/gtrue/true.go index 5b7f30c..cf6c67d 100644 --- a/src/tool/gtrue/true.go +++ b/src/tool/gtrue/true.go @@ -1,5 +1,5 @@ package gtrue -func Run(args []string) { -} +import "github.com/surdeus/gomtool/src/mtool" +func Run(flags *mtool.Flags) {} diff --git a/src/tool/ls/ls.go b/src/tool/ls/ls.go index fd6d79d..aa674c5 100644 --- a/src/tool/ls/ls.go +++ b/src/tool/ls/ls.go @@ -2,17 +2,15 @@ package ls import( "os" "fmt" - "flag" "strings" "regexp" "path" + "github.com/surdeus/gomtool/src/mtool" ) var( listHidden bool args []string - arg0 string - flagSet *flag.FlagSet ) var slashRegexp = regexp.MustCompile("/+") @@ -126,30 +124,25 @@ ls(p string, fold int) error { return nil } -func Run(argv []string) { - arg0 = argv[0] - args = argv[1:] - flagSet = flag.NewFlagSet(arg0, flag.ExitOnError) +func Run(flagSet *mtool.Flags) { var foldLvl int flagSet.IntVar(&foldLvl, "r", 1, "List recursively with choosing deepness, can't be negative or zero.") flagSet.BoolVar(&listHidden, "a", false, "List hidden files.") - flagSet.Parse(args) + flagSet.Parse() args = flagSet.Args() if foldLvl<0 { flagSet.Usage() - os.Exit(1) } if foldLvl==0 && len(args)==0 { flagSet.Usage() - os.Exit(1) } if len(args) == 0 { foldLvl -= 1 if l, e := ReadDir(".") ; e != nil { - fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) + fmt.Fprintf(os.Stderr, "%s.\n", e) } else { for _, f := range l { if !shouldList(f.Name()) { @@ -162,8 +155,7 @@ func Run(argv []string) { e := ls(f.Name(), foldLvl) if e!=nil { fmt.Fprintf(os.Stderr, - "%s: %s\n", - arg0, e) + "%s\n", e) } } } @@ -172,7 +164,7 @@ func Run(argv []string) { for _, p := range args { e := ls(p, foldLvl) if e != nil { - fmt.Fprintf(os.Stderr, "%s: %s\n", arg0, e) + fmt.Fprintf(os.Stderr, "%s\n", e) } } diff --git a/src/tool/mergelbl/main.go b/src/tool/mergelbl/main.go index b5d6508..3170933 100644 --- a/src/tool/mergelbl/main.go +++ b/src/tool/mergelbl/main.go @@ -4,11 +4,11 @@ import( "os" "fmt" "bufio" - "flag" "log" + "github.com/surdeus/gomtool/src/mtool" ) -func Run(args []string) { +func Run(flagSet *mtool.Flags) { var( e error buf string @@ -16,15 +16,8 @@ func Run(args []string) { rsep := '\n' wsep := "\n" //del := "" - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "usage: %s .. [fileN]\n", arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() + flagSet.Parse() + args := flagSet.Args() files := make([]*os.File, len(args)) for i, v := range args { diff --git a/src/tool/mkdir/mkdir.go b/src/tool/mkdir/mkdir.go index 217048f..ec47b77 100644 --- a/src/tool/mkdir/mkdir.go +++ b/src/tool/mkdir/mkdir.go @@ -1,29 +1,22 @@ package mkdir import ( - "flag" "fmt" "os" "github.com/surdeus/goblin/src/pathx" + "github.com/surdeus/gomtool/src/mtool" ) -func Run(args []string) { - arg0 := args[0] - args = args[1:] +func Run(flagSet *mtool.Flags) { var ( parentFlag bool modeArg int ) - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) flagSet.BoolVar(&parentFlag, "p", false, "No error if existing, make parent as needed.") flagSet.IntVar(&modeArg, "m", 0766, "Set file `mode`.") - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] [files]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() + flagSet.Parse() + args := flagSet.Args() if len(args) == 0 { flagSet.Usage() os.Exit(1) @@ -38,7 +31,7 @@ func Run(args []string) { e = os.Mkdir(pth, mode) } if e != nil { - fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) + fmt.Fprintf(os.Stderr, "%s\n", e) } } } diff --git a/src/tool/noext/noext.go b/src/tool/noext/noext.go index dd67104..9633694 100644 --- a/src/tool/noext/noext.go +++ b/src/tool/noext/noext.go @@ -3,8 +3,7 @@ package noext import( "fmt" - "flag" - "os" + "github.com/surdeus/gomtool/src/mtool" ) var( @@ -25,15 +24,9 @@ func NoExt(p string) string { return p[:i] } -func Run(argv []string) { - arg0 = argv[0] - args = argv[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "usage: %s [files]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() +func Run(flagSet *mtool.Flags) { + flagSet.Parse() + args := flagSet.Args() + if len(args) < 1 { flagSet.Usage() } fmt.Printf("%s", NoExt(args[0])) } diff --git a/src/tool/quote/quote.go b/src/tool/quote/quote.go index 6910eae..f61a65f 100644 --- a/src/tool/quote/quote.go +++ b/src/tool/quote/quote.go @@ -4,10 +4,10 @@ package quote import( "os" "io" - "flag" "fmt" "unicode" "bufio" + "github.com/surdeus/gomtool/src/mtool" ) func HasWhiteSpace(s string) bool { @@ -19,16 +19,8 @@ func HasWhiteSpace(s string) bool { return false } -func Run(args []string) { - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() +func Run(flagSet *mtool.Flags) { + flagSet.Parse() r := bufio.NewReader(os.Stdin) for{ diff --git a/src/tool/read/main.go b/src/tool/read/main.go index 6955268..dcdb1f3 100644 --- a/src/tool/read/main.go +++ b/src/tool/read/main.go @@ -3,26 +3,18 @@ package read import( "os" "bufio" - "flag" "fmt" + "github.com/surdeus/gomtool/src/mtool" ) var( nLines int ) -func Run(args []string) { - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) +func Run(flagSet *mtool.Flags) { 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() + flagSet.Parse() + //args := flagSet.Args() if nLines <= 0 { flagSet.Usage() diff --git a/src/tool/sort/sort.go b/src/tool/sort/sort.go index dc92c4c..228acf0 100644 --- a/src/tool/sort/sort.go +++ b/src/tool/sort/sort.go @@ -4,14 +4,11 @@ import ( "fmt" "os" "sort" - "flag" "github.com/surdeus/goblin/src/input" + "github.com/surdeus/gomtool/src/mtool" ) -func Run(args []string) { - flagSet := flag.NewFlagSet(args[0], flag.ExitOnError) - flagSet.Parse(args[1:]) - +func Run(flagSet *mtool.Flags) { lines, _ := input.ReadAllLines(os.Stdin) sort.Strings(lines) for _, l := range lines { diff --git a/src/tool/tac/tac.go b/src/tool/tac/tac.go index 2ca431d..b1108db 100644 --- a/src/tool/tac/tac.go +++ b/src/tool/tac/tac.go @@ -3,9 +3,9 @@ package tac import( "os" "io" - "flag" "fmt" "bufio" + "github.com/surdeus/gomtool/src/mtool" ) func reverse(a []string) chan string { @@ -47,21 +47,14 @@ func ftac(f *os.File) error { return nil } -func Run(args []string) { - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.Usage = func () { - fmt.Fprintf(os.Stderr, "Usage of %s: %s [files]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() +func Run(flagSet *mtool.Flags) { + flagSet.Parse() + args := flagSet.Args() if len(args)>0 { for _, p := range args { e := tac(p) if e != nil { - fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) + fmt.Fprintf(os.Stderr, "%s.\n", e) } } } else { diff --git a/src/tool/uniq/uniq.go b/src/tool/uniq/uniq.go index 682f06f..eb14f91 100644 --- a/src/tool/uniq/uniq.go +++ b/src/tool/uniq/uniq.go @@ -4,25 +4,18 @@ package uniq import( "os" "fmt" - "flag" "bufio" "io" + "github.com/surdeus/gomtool/src/mtool" ) -func Run(args []string) { +func Run(flagSet *mtool.Flags) { var( Uflag bool ) - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) flagSet.BoolVar(&Uflag, "U", false, "Print every line just one time.") - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] [string]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() + flagSet.Parse() + //args := flagSet.Args() r := bufio.NewReader(os.Stdin) u := make(map[string]int) diff --git a/src/tool/urlprs/urlprs.go b/src/tool/urlprs/urlprs.go index dbece0f..10e8334 100644 --- a/src/tool/urlprs/urlprs.go +++ b/src/tool/urlprs/urlprs.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "net/url" + "github.com/surdeus/gomtool/src/mtool" ) var nilStr = "_" @@ -16,10 +17,13 @@ func printNil(s string) { fmt.Println(nilStr) } } -func Run(args []string) { +func Run(flags *mtool.Flags) { nilStr = "_" - s := args[1] + flags.Parse() + args := flags.Args() + if len(args) < 1 { flags.Usage() } + s := args[0] u, err := url.Parse(s) if err != nil { diff --git a/src/tool/wc/main.go b/src/tool/wc/main.go index ea8f9af..3ddbf2d 100644 --- a/src/tool/wc/main.go +++ b/src/tool/wc/main.go @@ -6,8 +6,8 @@ import ( "bufio" "fmt" "unicode" - "flag" "strconv" + "github.com/surdeus/gomtool/src/mtool" ) var ( @@ -46,21 +46,17 @@ func finish() { os.Exit(0) } -func Run(args []string) { +func Run(flagSet *mtool.Flags) { var ( r rune siz int ) - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) - flagSet.BoolVar(&flags[charsFlag], "c", false, "print amount of chars(bytes)") flagSet.BoolVar(&flags[runesFlag], "r", false, "print amount of runes in UTF stream") flagSet.BoolVar(&flags[wordsFlag], "w", false, "print amount of words") flagSet.BoolVar(&flags[linesFlag], "l", false, "print amount of lines") - flagSet.Parse(args) + flagSet.Parse() for i, v := range flags { if v { diff --git a/src/tool/yes/yes.go b/src/tool/yes/yes.go index 9573cac..85844a7 100644 --- a/src/tool/yes/yes.go +++ b/src/tool/yes/yes.go @@ -4,9 +4,9 @@ package yes import( "os" "fmt" - "flag" "strings" "github.com/surdeus/goblin/src/input" + "github.com/surdeus/gomtool/src/mtool" ) var( nArg int @@ -24,24 +24,18 @@ func yes(s string){ } } -func Run(args []string) { +func Run(flagSet *mtool.Flags) { var( stdinFlag bool nFlag bool s string ) - arg0 := args[0] - args = args[1:] - flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) flagSet.BoolVar(&stdinFlag, "s", false, "Read string from stdin.") flagSet.BoolVar(&nFlag, "n", false, "Do not add net line character.") flagSet.IntVar(&nArg, "N", -1, "Repeat input N times. Negative value means infinite cycle.") - flagSet.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage of %s: %s [options] [string]\n", arg0, arg0) - flagSet.PrintDefaults() - } - flagSet.Parse(args) - args = flagSet.Args() + + flagSet.Parse() + args := flagSet.Args() if stdinFlag { in, _ := input.ReadAllRaw(os.Stdin)