diff --git a/main.go b/main.go index 1b13999..5e7331f 100644 --- a/main.go +++ b/main.go @@ -131,6 +131,7 @@ 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:] @@ -296,7 +297,6 @@ func runNuv(baseDir string, args []string) error { } debug("Found plugin", plgDir) - os.Setenv("NUV_ROOT", plgDir) if err := Nuv(plgDir, args[2:]); err != nil { log.Fatalf("error: %s", err.Error()) } @@ -312,6 +312,8 @@ func setupNuvPwd() { //nolint:errcheck os.Setenv("NUV_PWD", dir) } + + trace("set NUV_PWD", os.Getenv("NUV_PWD")) } func buildConfigMap(nuvRootPath string, configPath string) (*config.ConfigMap, error) { diff --git a/nuv.go b/nuv.go index bb23917..4c90831 100644 --- a/nuv.go +++ b/nuv.go @@ -162,7 +162,7 @@ func loadSavedArgs() []string { // Nuv parses args moving into the folder corresponding to args // then parses them with docopts and invokes the task func Nuv(base string, args []string) error { - trace("Nuv run with", args) + trace("Nuv run in", base, "with", args) // go down using args as subcommands err := os.Chdir(base) debug("Nuv chdir", base) diff --git a/tests/plugin.bats b/tests/plugin.bats index c71877c..449dabd 100644 --- a/tests/plugin.bats +++ b/tests/plugin.bats @@ -20,6 +20,7 @@ setup() { load 'test_helper/bats-assert/load' export NO_COLOR=1 export NUV_NO_LOG_PREFIX=1 + export NUV_BRANCH="0.3.0" } @test "nuv prints 'Plugins:'" { @@ -54,12 +55,52 @@ setup() { assert_line 'simple' } +@test "original nuv sub simple still works" { + run nuv sub simple + assert_line 'simple' +} + @test "config in plugin nuvroot is added with prefix" { run nuv -config -d assert_line 'PLUGIN_KEY=value' assert_line 'PLUGIN_ANOTHER_KEY=a plugin value' } +@test "other plugin without olaris is shown" { + cd testdata + run nuv -update + run nuv + assert_line 'Plugins:' + assert_line " other (local)" + run rm -rf ~/.nuv/olaris +} + +@test "other sub simple prints simple" { + cd testdata + run nuv -update + run nuv other sub simple + assert_line 'simple' + run rm -rf ~/.nuv/olaris +} + +@test "other tool runs nuv tool" { + cd testdata + run nuv -update + run nuv other tool + assert_line 'hello' + run rm -rf ~/.nuv/olaris +} + +@test "other command runs nuv command" { + cd testdata + run nuv -update + run nuv other command + assert_line 'nothing installed yet' + run rm -rf ~/.nuv/olaris +} + +# Plugin Tool Tests + @test "nuv -plugin with wrong name" { run nuv -plugin https://github.com/giusdp/olari assert_line "error: plugin repository names must start with 'olaris-'" diff --git a/tests/testdata/olaris-other/nuvfile.yml b/tests/testdata/olaris-other/nuvfile.yml new file mode 100644 index 0000000..b811f80 --- /dev/null +++ b/tests/testdata/olaris-other/nuvfile.yml @@ -0,0 +1,32 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +version: "3" +tasks: + sub: + desc: sub command + + tool: + desc: tool command (base64 -> hello) + cmds: + - nuv -base64 -d aGVsbG8= + + command: + desc: run nuv setup status + cmds: + - nuv setup status diff --git a/tests/testdata/olaris-other/nuvroot.json b/tests/testdata/olaris-other/nuvroot.json new file mode 100644 index 0000000..4f7f8f1 --- /dev/null +++ b/tests/testdata/olaris-other/nuvroot.json @@ -0,0 +1,6 @@ +{ + "version": "0.3.0", + "config": { + "key": "value" + } +} \ No newline at end of file diff --git a/tests/testdata/olaris-other/sub/nuvfile.yml b/tests/testdata/olaris-other/sub/nuvfile.yml new file mode 100644 index 0000000..f19605b --- /dev/null +++ b/tests/testdata/olaris-other/sub/nuvfile.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +version: "3" + +tasks: + simple: + desc: simple + cmds: + - echo simple diff --git a/tests/update.bats b/tests/update.bats index 29cd18c..450db3e 100644 --- a/tests/update.bats +++ b/tests/update.bats @@ -23,6 +23,7 @@ setup() { } @test "nuv -update" { + run rm -rf ~/.nuv/olaris run nuv -update assert_line "Nuvfiles downloaded successfully" assert_success diff --git a/tools/echo.go b/tools/echo.go index 5a5a9a0..c072658 100644 --- a/tools/echo.go +++ b/tools/echo.go @@ -130,7 +130,8 @@ func echoIfExistsTool() error { func printEchoIfUsage() { fmt.Println(`Usage: echoif -echoif is a utility that echoes the value of if the exit code of the previous command is 0, echoes the value of `) +echoif is a utility that echoes the value of if the exit code of the previous command is 0, +echoes the value of otherwise`) } func printEchoIfEmptyUsage() {