From e4a8bdeb13f7710012d740dd4fd00f9deb3f1d43 Mon Sep 17 00:00:00 2001 From: d4rkstar Date: Sun, 2 Jun 2024 19:09:59 +0200 Subject: [PATCH 1/3] feat: nuv -info and -version should only report version and exit moved the code that checks these arguments before the olaris checks. Should resolve https://github.com/nuvolaris/nuvolaris/issues/361 --- main.go | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index cf0a473..2964d11 100644 --- a/main.go +++ b/main.go @@ -124,6 +124,32 @@ func main() { setupBinPath(tools.NuvCmd) } + // check if first argument is help, info version: report output and exit + trace("OS args:", os.Args) + args := os.Args + + if len(args) > 1 && len(args[1]) > 0 && args[1][0] == '-' { + cmd := args[1][1:] + switch cmd { + case "info": + info() + os.Exit(0) + + case "help": + tools.Help() + os.Exit(0) + + case "version": + fmt.Println(NuvVersion) + os.Exit(0) + + case "v": + fmt.Println(NuvVersion) + os.Exit(0) + + } + } + nuvHome, err := homedir.Expand("~/.nuv") if err != nil { log.Fatalf("error: %s", err.Error()) @@ -160,9 +186,6 @@ func main() { // first argument with prefix "-" is an embedded tool // using "-" or "--" or "-task" invokes embedded task - trace("OS args:", os.Args) - args := os.Args - if len(args) > 1 && len(args[1]) > 0 && args[1][0] == '-' { cmd := args[1][1:] if cmd == "" || cmd == "-" || cmd == "task" { @@ -174,16 +197,6 @@ func main() { } switch cmd { - case "version": - fmt.Println(NuvVersion) - case "v": - fmt.Println(NuvVersion) - - case "info": - info() - - case "help": - tools.Help() case "serve": nuvRootDir := getRootDirOrExit() From 287f29b2afa5a1fcbc4a7eae52822d5ef736701e Mon Sep 17 00:00:00 2001 From: d4rkstar Date: Sun, 2 Jun 2024 19:23:23 +0200 Subject: [PATCH 2/3] updated comment --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 2964d11..bf22093 100644 --- a/main.go +++ b/main.go @@ -124,7 +124,7 @@ func main() { setupBinPath(tools.NuvCmd) } - // check if first argument is help, info version: report output and exit + // check if first argument is help, info or version: report output and exit trace("OS args:", os.Args) args := os.Args @@ -146,7 +146,6 @@ func main() { case "v": fmt.Println(NuvVersion) os.Exit(0) - } } From d4bde6ab8b14ae5f8b5f6b5c74a00a9413edc754 Mon Sep 17 00:00:00 2001 From: d4rkstar Date: Sun, 2 Jun 2024 19:54:08 +0200 Subject: [PATCH 3/3] fixed integration test --- main.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index bf22093..f8d3211 100644 --- a/main.go +++ b/main.go @@ -124,6 +124,15 @@ func main() { setupBinPath(tools.NuvCmd) } + nuvHome, err := homedir.Expand("~/.nuv") + if err != nil { + log.Fatalf("error: %s", err.Error()) + } + + setupTmp() + setNuvPwdEnv() + setNuvRootPluginEnv() + // check if first argument is help, info or version: report output and exit trace("OS args:", os.Args) args := os.Args @@ -149,11 +158,6 @@ func main() { } } - nuvHome, err := homedir.Expand("~/.nuv") - if err != nil { - log.Fatalf("error: %s", err.Error()) - } - // Check if olaris exists. If not, run `-update` to auto setup olarisDir := joinpath(joinpath(nuvHome, getNuvBranch()), "olaris") if !isDir(olarisDir) { @@ -169,9 +173,6 @@ func main() { } } - setupTmp() - setNuvPwdEnv() - setNuvRootPluginEnv() if err := setNuvOlarisHash(olarisDir); err != nil { warn("unable to set NUV_OLARIS...", err.Error()) }