You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
492 B
36 lines
492 B
6 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
p "path"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func usage() {
|
||
|
fmt.Printf("usage: %v path [suffix]\n", os.Args[0])
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
|
||
|
func basename(path, suffix string) string {
|
||
|
result := p.Base(path)
|
||
|
if suffix == "" {
|
||
|
return result
|
||
|
}
|
||
|
return strings.SplitN(result, suffix, 2)[0]
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
if len(os.Args) == 1 || len(os.Args) > 3 {
|
||
|
usage()
|
||
|
}
|
||
|
|
||
|
path := os.Args[1]
|
||
|
suffix := ""
|
||
|
if len(os.Args) == 3 {
|
||
|
suffix = os.Args[2]
|
||
|
}
|
||
|
|
||
|
fmt.Println(basename(path, suffix))
|
||
|
}
|