basename: init.

This commit is contained in:
k1574 2021-05-18 23:04:49 +05:00
parent abcd59b1ea
commit f03faa2c86
2 changed files with 44 additions and 0 deletions

42
basename/run.go Normal file
View file

@ -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
}

View file

@ -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,