Default package name to . when not specified

When running tinygo build, and the positional argument for the
package is not specified, default it to "."
Этот коммит содержится в:
Carolyn Van Slyck 2019-06-18 08:22:26 -05:00 коммит произвёл Ron Evans
родитель ed7c242a09
коммит ce9b21a270

19
main.go
Просмотреть файл

@ -640,8 +640,11 @@ func main() {
usage() usage()
os.Exit(1) os.Exit(1)
} }
if flag.NArg() != 1 { pkgName := "."
fmt.Fprintln(os.Stderr, "No package specified.") if flag.NArg() == 1 {
pkgName = flag.Arg(0)
} else if flag.NArg() > 1 {
fmt.Fprintln(os.Stderr, "build only accepts a single positional argument: package name, but multiple were specified")
usage() usage()
os.Exit(1) os.Exit(1)
} }
@ -649,7 +652,7 @@ func main() {
if target == "" && filepath.Ext(*outpath) == ".wasm" { if target == "" && filepath.Ext(*outpath) == ".wasm" {
target = "wasm" target = "wasm"
} }
err := Build(flag.Arg(0), *outpath, target, config) err := Build(pkgName, *outpath, target, config)
handleCompilerError(err) handleCompilerError(err)
case "build-builtins": case "build-builtins":
// Note: this command is only meant to be used while making a release! // Note: this command is only meant to be used while making a release!
@ -692,11 +695,15 @@ func main() {
err := Run(flag.Arg(0), *target, config) err := Run(flag.Arg(0), *target, config)
handleCompilerError(err) handleCompilerError(err)
case "test": case "test":
pkgRoot := "." pkgName := "."
if flag.NArg() == 1 { if flag.NArg() == 1 {
pkgRoot = flag.Arg(0) pkgName = flag.Arg(0)
} else if flag.NArg() > 1 {
fmt.Fprintln(os.Stderr, "test only accepts a single positional argument: package name, but multiple were specified")
usage()
os.Exit(1)
} }
err := Test(pkgRoot, *target, config) err := Test(pkgName, *target, config)
handleCompilerError(err) handleCompilerError(err)
case "clean": case "clean":
// remove cache directory // remove cache directory