Skip to content

Commit

Permalink
Merge pull request #76 from giusdp/main
Browse files Browse the repository at this point in the history
remove NUV_ROOT overwrite
  • Loading branch information
francescotimperi authored Aug 1, 2023
2 parents 4ac569b + a0f4bfc commit 6ee82a3
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 3 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down Expand Up @@ -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())
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion nuv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions tests/plugin.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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:'" {
Expand Down Expand Up @@ -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-'"
Expand Down
32 changes: 32 additions & 0 deletions tests/testdata/olaris-other/nuvfile.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/testdata/olaris-other/nuvroot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "0.3.0",
"config": {
"key": "value"
}
}
24 changes: 24 additions & 0 deletions tests/testdata/olaris-other/sub/nuvfile.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ setup() {
}

@test "nuv -update" {
run rm -rf ~/.nuv/olaris
run nuv -update
assert_line "Nuvfiles downloaded successfully"
assert_success
Expand Down
3 changes: 2 additions & 1 deletion tools/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ func echoIfExistsTool() error {
func printEchoIfUsage() {
fmt.Println(`Usage: echoif <a> <b>
echoif is a utility that echoes the value of <a> if the exit code of the previous command is 0, echoes the value of <b>`)
echoif is a utility that echoes the value of <a> if the exit code of the previous command is 0,
echoes the value of <b> otherwise`)
}

func printEchoIfEmptyUsage() {
Expand Down

0 comments on commit 6ee82a3

Please sign in to comment.