From f97c9d5f8eb8c3b7ea9bf7eefcf9f26e4e9c3b6f Mon Sep 17 00:00:00 2001 From: Giuseppe De Palma Date: Fri, 12 Jan 2024 11:34:31 +0100 Subject: [PATCH] fix: coreutils install --- README.md | 1 + bin/nuvfile.yml | 6 ++++-- tests/coreutils.bats | 28 ++++++++++++++++++++++++++++ tools/util.go | 20 ++++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/coreutils.bats diff --git a/README.md b/README.md index 002d8e3..59c8b9b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ set, `nuv -login` will prompt for the password. It is useful for tests and non-i - `NUV_ROOT_PLUGIN` is the folder where `nuv` looks for plugins. If not defined, it defaults to the same directory where `nuv` is located. - `NUV_OLARIS` holds the head commit hash of the used olaris repo. You can see the hash with `nuv -info`. ## Where `nuv` looks for binaries +- `NUV_USE_COREUTILS` enables the use of [coreutils](https://github.com/uutils/coreutils) instead of the current unix tools implementation. They will eventually replace the current tools. Nuv requires some binary command line tools to work with ("bins"). diff --git a/bin/nuvfile.yml b/bin/nuvfile.yml index 70c263e..191503e 100644 --- a/bin/nuvfile.yml +++ b/bin/nuvfile.yml @@ -210,10 +210,11 @@ tasks: - curl -sL -ccookie.txt -o{{.TGT}}{{.ARC2}} {{.SRC}} - rm cookie.txt - mkdir {{.TGT}}-extract - - '{{if eq .OS "windows"}}unzip.exe {{.TGT}}{{.ARC2}}{{else}}/usr/bin/tar xvzf {{.TGT}}{{.ARC2}} -C {{.TGT}}-extract --strip-components{{end}}' - - '{{if eq .OS "windows"}} mv coreutils-0.0.23-x86_64-pc-windows-msvc/{{.TGT}}{{EXE}} . {{else}} mv {{.TGT}}-extract/{{.TGT}}{{.EXE}} . {{end}}' + - '{{if eq .OS "windows"}}unzip.exe {{.TGT}}{{.ARC2}}{{else}}/usr/bin/tar xvzf {{.TGT}}{{.ARC2}} -C {{.TGT}}-extract --strip-components 1{{end}}' + - '{{if eq .OS "windows"}} mv coreutils-0.0.23-x86_64-pc-windows-msvc/{{.TGT}}{{.EXE}} . {{else}} mv {{.TGT}}-extract/{{.TGT}}{{.EXE}} . {{end}}' - '{{if eq .OS "windows"}} rm -r coreutils-0.0.23-x86_64-pc-windows-msvc {{else}} rm -r {{.TGT}}-extract {{end}}' - rm -r {{.TGT}}{{.ARC2}} + - rm -r {{.TGT}}-extract status: - test -e {{.TGT}}{{.EXE}} @@ -274,6 +275,7 @@ tasks: - task: eksctl - task: grep.exe - task: ntfy + - task: coreutils # currently not used #- task: mc # it has "licensing complications" #- task: kops diff --git a/tests/coreutils.bats b/tests/coreutils.bats new file mode 100644 index 0000000..ad6af8d --- /dev/null +++ b/tests/coreutils.bats @@ -0,0 +1,28 @@ +# 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. + +setup() { + load 'test_helper/bats-support/load' + load 'test_helper/bats-assert/load' + export NO_COLOR=1 + export NUV_USE_COREUTILS=1 +} + +@test "-cat with coreutils" { + run echo "$(echo "Hello World" | nuv -cat + assert_line "Hello World" +} \ No newline at end of file diff --git a/tools/util.go b/tools/util.go index d25f196..de9fe5c 100644 --- a/tools/util.go +++ b/tools/util.go @@ -18,6 +18,7 @@ package tools import ( "fmt" + "os" "github.com/nuvolaris/someutils" "github.com/nuvolaris/someutils/some" @@ -44,9 +45,24 @@ func IsUtil(name string) bool { func RunUtil(name string, args []string) (int, error) { if IsUtil(name) { full := append([]string{name}, args...) - //fmt.Println(name, full) - err, code := someutils.Call(name, full) + fmt.Println(name, full) + var err error + var code int + if useCoreutils() { + code, err = runCoreUtils(name, args) + + } else { + err, code = someutils.Call(name, full) + } return code, err } return 1, fmt.Errorf("command %s not found", name) } + +func useCoreutils() bool { + return os.Getenv("NUV_USE_COREUTILS") != "" +} + +func runCoreUtils(name string, args []string) (int, error) { + return 0, nil +}