Skip to content

Commit

Permalink
fix: coreutils install
Browse files Browse the repository at this point in the history
  • Loading branch information
giusdp committed Jan 12, 2024
1 parent 8892895 commit f97c9d5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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").

Expand Down
6 changes: 4 additions & 2 deletions bin/nuvfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/coreutils.bats
Original file line number Diff line number Diff line change
@@ -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"
}
20 changes: 18 additions & 2 deletions tools/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tools

import (
"fmt"
"os"

"github.com/nuvolaris/someutils"
"github.com/nuvolaris/someutils/some"
Expand All @@ -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
}

0 comments on commit f97c9d5

Please sign in to comment.