Skip to content

Commit

Permalink
Move to go.nhat.io
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm committed Aug 27, 2022
1 parent 047d5fe commit 0fd22c2
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 217 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
name: lint

on:
push:
tags:
- v*
branches:
- master
- main
pull_request:

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: golangci-lint

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- id: get-lint-version
run: |
make golangci-lint-version
- name: lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.46.2
version: ${{ steps.get-lint-version.outputs.GOLANGCI_LINT_VERSION }}

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:

env:
GO111MODULE: "on"
GO_LATEST_VERSION: "1.18.x"
GO_LATEST_VERSION: "1.19.x"

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
go-version: [ 1.17.x, 1.18.x ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ 1.17.x, 1.18.x, 1.19.x ]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: 'update-registry'

on:
push:
tags:
- v*
workflow_dispatch:

env:
MODULE_NAME: surveyexpect

jobs:
notify:
runs-on: ubuntu-latest
strategy:
matrix:
registry: [ go.nhat.io, go-staging.nhat.io ]
steps:
- name: notify ${{ matrix.registry }}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build
repo: nhatthm/${{ matrix.registry }}
token: ${{ secrets.REGISTRY_TOKEN }}
inputs: '{"modules": "${{ env.MODULE_NAME }}"}'
ref: 'master'
6 changes: 4 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ linters:
- gomnd
- ifshort
- interfacer
- ireturn
- lll
- maligned
- nonamedreturns
- nolintlint # https://github.com/golangci/golangci-lint/issues/3063
- paralleltest
- scopelint
- tagliatelle
- testpackage
- wrapcheck
- varnamelen
- wrapcheck

issues:
exclude-use-default: false
Expand Down
29 changes: 21 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
VENDORDIR = vendor
VENDOR_DIR = vendor

GO ?= go
GOLANGCI_LINT ?= golangci-lint
GOLANGCI_LINT_VERSION ?= v1.48.0

.PHONY: $(VENDORDIR) lint test test-unit
GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)

$(VENDORDIR):
@mkdir -p $(VENDORDIR)
.PHONY: $(VENDOR_DIR)
$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
@$(GO) mod vendor

lint:
@$(GOLANGCI_LINT) run
.PHONY: lint
lint: $(GOLANGCI_LINT) $(VENDOR_DIR)
@$(GOLANGCI_LINT) run -c .golangci.yaml

.PHONY: test
test: test-unit

## Run unit tests
.PHONY: test-unit
test-unit:
@echo ">> unit test"
@$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./...

.PHONY: golangci-lint-version
golangci-lint-version:
@echo "::set-output name=GOLANGCI_LINT_VERSION::$(GOLANGCI_LINT_VERSION)"

$(GOLANGCI_LINT):
@echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin "$(GOLANGCI_LINT_VERSION)"
@mv ./bin/golangci-lint $(GOLANGCI_LINT)
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/surveyexpect)](https://github.com/nhatthm/surveyexpect/releases/latest)
[![Build Status](https://github.com/nhatthm/surveyexpect/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/surveyexpect/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/nhatthm/surveyexpect/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/surveyexpect)
[![Go Report Card](https://goreportcard.com/badge/github.com/nhatthm/surveyexpect)](https://goreportcard.com/report/github.com/nhatthm/surveyexpect)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/nhatthm/surveyexpect)
[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/surveyexpect)](https://goreportcard.com/report/go.nhat.io/surveyexpect)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/surveyexpect)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)

**surveyexpect** is an Expect library for [AlecAivazis/survey/v2](https://github.com/AlecAivazis/survey)

## Prerequisites

- `Go >= 1.16`
- `Go >= 1.17`

## Install

```bash
go get github.com/nhatthm/surveyexpect
go get go.nhat.io/surveyexpect
```

## Usage

### Supported Types

Type | Supported | Supported Actions
:--- | :---: | :---
`Confirm` | ✓ | <ul><li>Answer `yes`, `no` or a custom one</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul>
`Editor` | ✘ | __*There is no plan for support*__
`Input` | ✓ | <ul><li>Answer</li><li>No answer</li><li>Suggestions with navigation (Arrow Up ``, Arrow Down ``, Tab ``, Esc ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul>
`Multiline` | ✓ | <ul><li>Answer</li><li>No answer</li><li>Interrupt (`^C`)</li></ul>
`Multiselect` | | <ul><li>Type to filter, delete</li><li>Navigation (Move Up ``, Move Down ``, Select None ``, Select All ``, Tab ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul>
`Password` | ✓ | <ul><li>Answer (+ check for `*`)</li><li>No answer</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul>
`Select` | ✓ | <ul><li>Type to filter, delete</li><li>Navigation (Move Up ``, Move Down ``, Tab ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul>
| Type | Supported | Supported Actions |
|:--------------|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Confirm` || <ul><li>Answer `yes`, `no` or a custom one</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul> |
| `Editor` || __*There is no plan for support*__ |
| `Input` || <ul><li>Answer</li><li>No answer</li><li>Suggestions with navigation (Arrow Up ``, Arrow Down ``, Tab ``, Esc ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul> |
| `Multiline` || <ul><li>Answer</li><li>No answer</li><li>Interrupt (`^C`)</li></ul> |
| `Multiselect` | | <ul><li>Type to filter, delete</li><li>Navigation (Move Up ``, Move Down ``, Select None ``, Select All ``, Tab ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul> |
| `Password` || <ul><li>Answer (+ check for `*`)</li><li>No answer</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul> |
| `Select` || <ul><li>Type to filter, delete</li><li>Navigation (Move Up ``, Move Down ``, Tab ``, Enter ``)</li><li>Interrupt (`^C`)</li><li>Ask for help</li></ul> |

### Expect

Expand Down Expand Up @@ -75,8 +75,8 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/nhatthm/surveyexpect"
"github.com/stretchr/testify/assert"
"go.nhat.io/surveyexpect"
)

func TestMyPackage(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Buffer struct {
// Write appends the contents of p to the buffer, growing the buffer as
// needed. The return value n is the length of p; err is always nil. If the
// buffer becomes too large, Write will panic with ErrTooLarge.
func (b *Buffer) Write(p []byte) (n int, err error) {
func (b *Buffer) Write(p []byte) (int, error) {
b.mutex.Lock()
defer b.mutex.Unlock()

Expand Down
23 changes: 12 additions & 11 deletions confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type ConfirmPrompt struct {

// ShowHelp sets help for the expectation.
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// ShowHelp("The file will be permanently deleted").
// Survey.ExpectConfirm("Are you sure to delete this file?").
// ShowHelp("The file will be permanently deleted").
func (c *ConfirmPrompt) ShowHelp(help string, options ...string) {
c.lock()
defer c.unlock()
Expand All @@ -31,8 +31,8 @@ func (c *ConfirmPrompt) ShowHelp(help string, options ...string) {

// Interrupt marks the answer is interrupted.
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Interrupt().
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Interrupt().
func (c *ConfirmPrompt) Interrupt() {
c.lock()
defer c.unlock()
Expand All @@ -42,8 +42,8 @@ func (c *ConfirmPrompt) Interrupt() {

// Yes sets "yes" as the answer to the prompt.
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Yes().
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Yes().
func (c *ConfirmPrompt) Yes() {
c.lock()
defer c.unlock()
Expand All @@ -54,8 +54,8 @@ func (c *ConfirmPrompt) Yes() {

// No sets "no" as the answer to the prompt.
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// No().
// Survey.ExpectConfirm("Are you sure to delete this file?").
// No().
func (c *ConfirmPrompt) No() {
c.lock()
defer c.unlock()
Expand All @@ -67,10 +67,11 @@ func (c *ConfirmPrompt) No() {
// Answer sets a custom answer to the prompt.
//
// If the answer is not not empty, the survey expects to have a feedback from the prompt:
// `Sorry, your reply was invalid: "hello world!" is not a valid answer, please try again.`
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Answer("hello world!").
// `Sorry, your reply was invalid: "hello world!" is not a valid answer, please try again.`
//
// Survey.ExpectConfirm("Are you sure to delete this file?").
// Answer("hello world!").
func (c *ConfirmPrompt) Answer(answer string) *ConfirmAnswer {
c.lock()
defer c.unlock()
Expand Down
4 changes: 2 additions & 2 deletions confirm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/AlecAivazis/survey/v2/terminal"
"github.com/stretchr/testify/assert"

"github.com/nhatthm/surveyexpect"
"github.com/nhatthm/surveyexpect/options"
"go.nhat.io/surveyexpect"
"go.nhat.io/surveyexpect/options"
)

func TestConfirm(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions cursor_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package surveyexpect
Expand Down
2 changes: 1 addition & 1 deletion expect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package surveyexpect_test
import (
"fmt"

"github.com/nhatthm/surveyexpect"
"go.nhat.io/surveyexpect"
)

type TestingT struct {
Expand Down
4 changes: 2 additions & 2 deletions expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func expectMultiSelect(options ...string) *MultiSelectExpect {
return &e
}

func breakdownOptions(options []string, indicator *regexp.Regexp) (breakdown []map[string]string, pad string) {
breakdown = make([]map[string]string, 0, len(options))
func breakdownOptions(options []string, indicator *regexp.Regexp) ([]map[string]string, string) {
breakdown := make([]map[string]string, 0, len(options))

var size int

Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/nhatthm/surveyexpect
module go.nhat.io/surveyexpect

go 1.17

Expand All @@ -13,12 +13,12 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ github.com/hinshun/vt10x v0.0.0-20220301184237-5011da428d02/go.mod h1:Q48J4R4Dvx
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
Expand All @@ -33,13 +33,13 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
Loading

0 comments on commit 0fd22c2

Please sign in to comment.