Skip to content

Commit

Permalink
Merge branch 'golangci' of github.com:gssbzn/promptui into gssbzn-gol…
Browse files Browse the repository at this point in the history
…angci
  • Loading branch information
jbowes committed Jan 11, 2020
2 parents 7064ee8 + bbfb055 commit 1b1eeb9
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
all-cover.txt
bin/
26 changes: 26 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
run:
deadline: 5m

issues:
# Disable maximums so we see all issues
max-per-linter: 0
max-same-issues: 0

# golangci-lint ignores missing docstrings by default. That's no good!
exclude-use-default: false

linters:
disable-all: true
enable:
- misspell
- golint
- goimports
- ineffassign
- deadcode
- gofmt
- govet
- structcheck
- unconvert
- megacheck
- typecheck
- varcheck
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Add support for configurable Stdin/Stdout on Prompt
- Add support for setting initial cursor position
- Switch to golangci-lint for linting

### Fixed

- Reduce tool-based deps, hopefully fixing any install issues


## [0.6.0] - 2019-11-29

### Added
Expand Down
53 changes: 17 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,40 @@
LINTERS=$(shell grep "// lint" tools/tools.go | awk '{gsub(/\"/, "", $$1); print $$1}' | awk -F / '{print $$NF}') \
gofmt \
vet

ci: $(LINTERS) cover
export GO111MODULE := on
export PATH := ./bin:$(PATH)

ci: bootstrap lint cover
.PHONY: ci

#################################################
# Bootstrapping for base golang package and tool deps
#################################################

CMD_PKGS=$(shell grep ' "' tools/tools.go | awk -F '"' '{print $$2}')

define VENDOR_BIN_TMPL
tools/vendor/bin/$(notdir $(1)): tools/vendor/$(1) | vendor tools/vendor
GOBIN=`pwd`/tools/vendor/bin sh -c 'cd tools && go install ./vendor/$(1)'
VENDOR_BINS += tools/vendor/bin/$(notdir $(1))
tools/vendor/$(1): tools/vendor
endef

$(foreach cmd_pkg,$(CMD_PKGS),$(eval $(call VENDOR_BIN_TMPL,$(cmd_pkg))))

$(patsubst %,%-bin,$(filter-out gofmt vet,$(LINTERS))): %-bin: tools/vendor/bin/%
gofmt-bin vet-bin:

tools/vendor: tools/go.sum
GO111MODULE=on sh -c 'cd tools && go mod vendor'

vendor: go.sum
GO111MODULE=on go mod vendor
bootstrap:
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.21.0
.PHONY: bootstrap

mod-update:
GO111MODULE=on go get -u -m
GO111MODULE=on go mod tidy
go get -u -m
go mod tidy

mod-tidy:
GO111MODULE=on go mod tidy
go mod tidy

.PHONY: $(CMD_PKGS)
.PHONY: mod-update mod-tidy

#################################################
# Test and linting
#################################################
# Run all the linters
lint:
bin/golangci-lint run ./...
.PHONY: lint

test: vendor
test:
CGO_ENABLED=0 go test $$(go list ./... | grep -v generated)
.PHONY: test

$(LINTERS): %: tools/vendor/bin/gometalinter %-bin tools/vendor
PATH=`pwd`/tools/vendor/bin:$$PATH gometalinter --tests --disable-all --vendor \
--deadline=5m -s data --enable $@ ./...

COVER_TEST_PKGS:=$(shell find . -type f -name '*_test.go' | grep -v vendor | rev | cut -d "/" -f 2- | rev | grep -v generated | sort -u)
COVER_TEST_PKGS:=$(shell find . -type f -name '*_test.go' | rev | cut -d "/" -f 2- | rev | grep -v generated | sort -u)
$(COVER_TEST_PKGS:=-cover): %-cover: all-cover.txt
@CGO_ENABLED=0 go test -v [email protected] -covermode=atomic ./$*
@if [ -f [email protected] ]; then \
Expand All @@ -62,7 +45,5 @@ $(COVER_TEST_PKGS:=-cover): %-cover: all-cover.txt
all-cover.txt:
echo "mode: atomic" > all-cover.txt

cover: vendor all-cover.txt $(COVER_TEST_PKGS:=-cover)

.PHONY: $(LINTERS) test
cover: all-cover.txt $(COVER_TEST_PKGS:=-cover)
.PHONY: cover all-cover.txt
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Interactive prompt for command-line applications.

We built Promptui because we wanted to make it easy and fun to explore cloud services with [manifold cli](https://github.com/manifoldco/manifold-cli).
We built Promptui because we wanted to make it easy and fun to explore cloud
services with [manifold cli](https://github.com/manifoldco/manifold-cli).

[Code of Conduct](./CODE_OF_CONDUCT.md) |
[Contribution Guidelines](./.github/CONTRIBUTING.md)
Expand Down
2 changes: 1 addition & 1 deletion cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func format(a []rune, c *Cursor) string {

out := make([]rune, 0)
if i < len(a) {
b = c.Cursor([]rune(a[i : i+1]))
b = c.Cursor(a[i : i+1])
out = append(out, a[:i]...) // does not include i
out = append(out, b...) // add the cursor
out = append(out, a[i+1:]...) // add the rest after i
Expand Down
11 changes: 8 additions & 3 deletions screenbuf/screenbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type ScreenBuf struct {
w io.Writer
buf *bytes.Buffer
reset bool
flush bool
cursor int
height int
}
Expand Down Expand Up @@ -77,11 +76,17 @@ func (s *ScreenBuf) Write(b []byte) (int, error) {
if err != nil {
return n, err
}
line := append(b, []byte("\n")...)
n, err = s.buf.Write(line)

n, err = s.buf.Write(b)
if err != nil {
return n, err
}

_, err = s.buf.Write([]byte("\n"))
if err != nil {
return n, err
}

s.height++
s.cursor++
return n, nil
Expand Down
6 changes: 2 additions & 4 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ type Select struct {
// For search mode to work, the Search property must be implemented.
StartInSearchMode bool

label string

list *list.List

// A function that determines how to render the cursor
Expand Down Expand Up @@ -282,7 +280,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)

cur.Backspace()
if len(cur.Get()) > 0 {
s.list.Search(string(cur.Get()))
s.list.Search(cur.Get())
} else {
s.list.CancelSearch()
}
Expand All @@ -293,7 +291,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
default:
if canSearch && searchMode {
cur.Update(string(line))
s.list.Search(string(cur.Get()))
s.list.Search(cur.Get())
}
}

Expand Down
19 changes: 0 additions & 19 deletions tools/go.mod

This file was deleted.

42 changes: 0 additions & 42 deletions tools/go.sum

This file was deleted.

11 changes: 0 additions & 11 deletions tools/tools.go

This file was deleted.

0 comments on commit 1b1eeb9

Please sign in to comment.