Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
test-vendoring:
executor: build-executor
environment:
- GO111MODULE=on
- GOFLAGS=-mod=vendor
GO111MODULE: 'on'
GOFLAGS: -mod=vendor
steps:
- checkout
- run: go mod tidy
Expand Down Expand Up @@ -76,15 +76,13 @@ jobs:
steps:
- checkout
- setup_remote_docker:
version: 18.06.0-ce
docker_layer_caching: true
version: 18.09.3
- run: make artifacts.tag latest.tag alpine.tag slim.tag

workflows:
version: 2.1
build-and-test:
jobs:
- test-vendoring
# - test-vendoring
- build
- test:
requires:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ gen-changelog:
github_changelog_generator --no-filter-by-milestone --exclude-labels duplicate,question,invalid,wontfix,admin

lint:
golangci-lint run -j $(LINT_PROCS)
golangci-lint run --disable wsl
Copy link
Copy Markdown
Owner Author

@hairyhenderson hairyhenderson Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling until bombsimon/wsl#38 is fixed it's fixed (but not downstreamed to golangci-lint yet)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, until golangci/golangci-lint#811 is fixed 😂


.PHONY: gen-changelog clean test build-x compress-all build-release build test-integration-docker gen-docs lint clean-images clean-containers docker-images
.DELETE_ON_ERROR:
Expand Down
7 changes: 7 additions & 0 deletions cmd/which/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,31 @@ func main() {

if all {
found := which.All(programs...)

if len(found) == 0 {
os.Exit(1)
}

fmt.Println(strings.Join(found, "\n"))

return
}

if silent {
found := which.Found(programs...)

if found {
return
}

os.Exit(1)
}

found := which.Which(programs...)

if found == "" {
os.Exit(1)
}

fmt.Println(found)
}
2 changes: 2 additions & 0 deletions internal/tests/integration/basic_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build integration

package integration

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/tests/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build integration

package integration

import (
Expand Down
19 changes: 14 additions & 5 deletions which.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func which(fs afero.Fs, program ...string) string {
}
}
}

return ""
}

Expand All @@ -43,6 +44,7 @@ func All(program ...string) []string {

func all(fs afero.Fs, program ...string) []string {
out := []string{}

for _, prog := range program {
for _, p := range getPath() {
candidate := filepath.Join(p, prog)
Expand All @@ -51,6 +53,7 @@ func all(fs afero.Fs, program ...string) []string {
}
}
}

return out
}

Expand All @@ -64,16 +67,19 @@ func found(fs afero.Fs, program ...string) bool {
count := 0
for _, prog := range program {
count = 0

for _, p := range getPath() {
candidate := filepath.Join(p, prog)
if isExec(fs, candidate) {
count++
}
}

if count == 0 {
return false
}
}

return count > 0
}

Expand All @@ -87,29 +93,32 @@ func getPath() []string {
}
}
}

return strings.Split(pathVar, string(os.PathListSeparator))
}

func keys(env []string) []string {
out := make([]string, len(env))

for i, v := range env {
parts := strings.SplitN(v, "=", 2)
out[i] = parts[0]
}

return out
}

// isExec returns true when the file at the given path is a regular file with
// the execute bit set (if on UNIX)
func isExec(fs afero.Fs, path string) bool {
fi, err := fs.Stat(path)
if os.IsNotExist(err) {

switch {
case os.IsNotExist(err):
return false
}
if fi.IsDir() {
case fi.IsDir():
return false
}
if fi.Mode()&0111 != 0 {
case fi.Mode()&0111 != 0:
return true
}
// Windows filesystems have no execute bit...
Expand Down
1 change: 1 addition & 0 deletions which_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func init() {
if err != nil {
panic(err)
}

_, err = f.WriteString("#!/bin/sh\necho hello world\n")
if err != nil {
panic(err)
Expand Down