From f03faa2c86508d66f1a4b052c1a7aae689917a3f Mon Sep 17 00:00:00 2001 From: k1574 Date: Tue, 18 May 2021 23:04:49 +0500 Subject: [PATCH] basename: init. --- basename/run.go | 42 ++++++++++++++++++++++++++++++++++++++++++ main.go | 2 ++ 2 files changed, 44 insertions(+) create mode 100644 basename/run.go diff --git a/basename/run.go b/basename/run.go new file mode 100644 index 0000000..d93d267 --- /dev/null +++ b/basename/run.go @@ -0,0 +1,42 @@ +package basename +/* Print file path without extension. */ + +import( + "fmt" + "flag" + "os" + "path" +) + +var( + arg0 string + args []string + slash = '/' +) + +func Base(p string) string { + return path.Base(p) +} + +func Run(argv []string) int { + status := 0 + 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() + + lasti := len(args) - 1 + for i, v := range args { + fmt.Printf("%s", Base(v)) + if i != lasti { + fmt.Println("") + } + } + + return status +} diff --git a/main.go b/main.go index 62247c4..e506673 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import( "goblin/urlprs" "goblin/noext" "goblin/mergelbl" + "goblin/basename" ) func main() { @@ -29,6 +30,7 @@ func main() { utilsMap := map[string] interface{} { + "basename" : basename.Run, "cat": cat.Run, "mkdir" : mkdir.Run, "echo" : echo.Run,