bb/tool/noext/noext.go

33 lines
470 B
Go
Raw Permalink Normal View History

2021-03-08 02:35:25 +03:00
package noext
/* Print file path without extension. */
import(
"fmt"
2024-05-15 21:07:35 +03:00
"surdeus.su/core/cli/mtool"
2021-03-08 02:35:25 +03:00
)
var(
arg0 string
args []string
dot = '.'
2021-05-18 20:54:36 +03:00
slash = '/'
2021-03-08 02:35:25 +03:00
)
func NoExt(p string) string {
l := len(p)-1
i := l
for ; rune(p[i])!=dot ; i -= 1 {
if rune(p[i]) == slash || i==0 {
return p
}
}
return p[:i]
}
2023-03-24 16:54:51 +03:00
func Run(flagSet *mtool.Flags) {
flagSet.Parse()
args := flagSet.Args()
if len(args) < 1 { flagSet.Usage() }
2021-03-08 02:35:25 +03:00
fmt.Printf("%s", NoExt(args[0]))
}