From ce9b21a270fdf84d5760e244d8ebb64cd25ccf90 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Tue, 18 Jun 2019 08:22:26 -0500 Subject: [PATCH] Default package name to . when not specified When running tinygo build, and the positional argument for the package is not specified, default it to "." --- main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 454ed73e..54612537 100644 --- a/main.go +++ b/main.go @@ -640,8 +640,11 @@ func main() { usage() os.Exit(1) } - if flag.NArg() != 1 { - fmt.Fprintln(os.Stderr, "No package specified.") + pkgName := "." + 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() os.Exit(1) } @@ -649,7 +652,7 @@ func main() { if target == "" && filepath.Ext(*outpath) == ".wasm" { target = "wasm" } - err := Build(flag.Arg(0), *outpath, target, config) + err := Build(pkgName, *outpath, target, config) handleCompilerError(err) case "build-builtins": // 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) handleCompilerError(err) case "test": - pkgRoot := "." + pkgName := "." 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) case "clean": // remove cache directory