Fix function and package names if the user supplied versions start with a digit.
This commit is contained in:
parent
55b35257df
commit
2985202b2b
12
main.go
12
main.go
|
@ -11,11 +11,12 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
APP_NAME = "bindata"
|
APP_NAME = "bindata"
|
||||||
APP_VERSION = "0.3"
|
APP_VERSION = "0.4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -61,6 +62,11 @@ func main() {
|
||||||
if len(*pkgname) == 0 {
|
if len(*pkgname) == 0 {
|
||||||
fmt.Fprintln(os.Stderr, "[w] No package name specified. Using 'main'.")
|
fmt.Fprintln(os.Stderr, "[w] No package name specified. Using 'main'.")
|
||||||
*pkgname = "main"
|
*pkgname = "main"
|
||||||
|
} else {
|
||||||
|
if unicode.IsDigit(int((*pkgname)[0])) {
|
||||||
|
// Identifier can't start with a digit.
|
||||||
|
*pkgname = "_" + *pkgname
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*funcname) == 0 {
|
if len(*funcname) == 0 {
|
||||||
|
@ -74,6 +80,10 @@ func main() {
|
||||||
file = strings.Replace(file, " ", "_", -1)
|
file = strings.Replace(file, " ", "_", -1)
|
||||||
file = strings.Replace(file, ".", "_", -1)
|
file = strings.Replace(file, ".", "_", -1)
|
||||||
file = strings.Replace(file, "-", "_", -1)
|
file = strings.Replace(file, "-", "_", -1)
|
||||||
|
if unicode.IsDigit(int(file[0])) {
|
||||||
|
// Identifier can't start with a digit.
|
||||||
|
file = "_" + file
|
||||||
|
}
|
||||||
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
|
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file)
|
||||||
*funcname = file
|
*funcname = file
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user