Skip to content

Commit

Permalink
deps: update go version and change CI Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-brito authored and rafaelsq committed Oct 16, 2021
1 parent 624c72a commit 1b88e69
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
- name: Set up Go 1.17
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.17
- name: Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 1
path: go/src/github.com/rafaelsq/wtc
- name: GolangCI-Lint
run: |
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s v1.19.1
./bin/golangci-lint run
- name: Test
run: go test -race -cover ./...
- name: GolangCI-Lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
skip-build-cache: true
skip-pkg-cache: true
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
run:
timeout: 1m

linters:
enable:
- lll
- gofmt
- revive
- exportloopref
- unparam

linters-settings:
lll:
line-length: 130
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WTC is a simple utility you can use to watch files and execute commands.
## Install

From master branch
`$ go get -u github.com/rafaelsq/wtc`
`$ go install github.com/rafaelsq/wtc@latest`

You can also install by release(linux64 only);
`$ curl -sfL --silent https://github.com/rafaelsq/wtc/releases/latest/download/wtc.linux64.tar.gz | tar -xzv && mv wtc $(go env GOPATH)/bin/`
Expand All @@ -29,12 +29,12 @@ Before you begin, ensure you have installed the latest version of Go. See the [G
$ wtc --help
USAGE:
wtc [[flags] [regex command]]
ex.: wtc
e.g.: wtc
// will read [.]wtc.y[a]ml
ex.: wtc "_test\.go$" "go test -cover {PKG}"
e.g.: wtc "_test\.go$" "go test -cover {PKG}"
wtc [flags]] [rule-name]
ex.: wtc -t rule-name
e.g.: wtc -t rule-name
wtc --no-trace "rule ruleb"
FLAGS:
-debounce int
Expand All @@ -47,7 +47,7 @@ FLAGS:
disable messages.
-t string
trig one or more rules by name
ex.: wtc -t ruleA
e.g.: wtc -t ruleA
wtc -t "ruleA ruleB"
```

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rafaelsq/wtc

go 1.13
go 1.17

require (
github.com/creack/pty v1.1.11
Expand Down
23 changes: 16 additions & 7 deletions pkg/wtc/wtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func ParseArgs() *Config {
fmt.Fprintf(
flag.CommandLine.Output(),
"USAGE:\nwtc [[flags] [regex command]]\n"+
"\tex.: wtc\n\t // will read [.]wtc.y[a]ml\n"+
"\tex.: wtc \"_test\\.go$\" \"go test -cover {PKG}\"\n\n"+
"wtc [flags]] [rule-name]\n\tex.: wtc -t rule-name\n\t wtc --no-trace \"rule ruleb\"\n"+
"\te.g.: wtc\n\t // will read [.]wtc.y[a]ml\n"+
"\te.g.: wtc \"_test\\.go$\" \"go test -cover {PKG}\"\n\n"+
"wtc [flags]] [rule-name]\n\te.g.: wtc -t rule-name\n\t wtc --no-trace \"rule ruleb\"\n"+
"FLAGS:\n",
)
flag.PrintDefaults()
Expand All @@ -102,7 +102,7 @@ func ParseArgs() *Config {
flag.StringVar(&configFilePath, "f", "", "wtc config file (default try to find [.]wtc.y[a]ml)")

var trigs string
flag.StringVar(&trigs, "t", "", "trig one or more rules by name\n\tex.: wtc -t ruleA\n\t wtc -t \"ruleA ruleB\"")
flag.StringVar(&trigs, "t", "", "trig one or more rules by name\n\te.g.: wtc -t ruleA\n\t wtc -t \"ruleA ruleB\"")

flag.Parse()

Expand Down Expand Up @@ -181,6 +181,9 @@ func Start(cfg *Config) {
// close current
if currentOut != nil {
_, err = (*currentOut).Write(currentArgs[1])
if err != nil {
log.Println(err)
}
}

// parse tpl
Expand Down Expand Up @@ -208,13 +211,19 @@ func Start(cfg *Config) {

// write start
_, err = currentOut.Write(currentArgs[0])
if err != nil {
log.Println(err)
}
}

if r.Rune == 0 || r.Rune == BR {
continue
}

_, err = fmt.Fprintf(currentOut, "%c", r.Rune)
if err != nil {
log.Println(err)
}
}
}()

Expand Down Expand Up @@ -462,20 +471,20 @@ func trig(rule *Rule, pkg, path string) error {
for _, e := range append(config.Env, rule.Env...) {
if strings.ToLower(e.Type) == "file" {
if e.Name == "" {
panic(fmt.Errorf("field \"name\" must point to a file"))
log.Fatal("field \"name\" must point to a file")
}

var body string
{
fileInfo, err := os.Stat(e.Name)
if err != nil {
panic(err)
log.Fatal(err)
}

if lastModified, ok := envFileLastModified[e.Name]; !ok || fileInfo.ModTime().Sub(lastModified) > 0 {
b, err := ioutil.ReadFile(e.Name)
if err != nil {
panic(err)
log.Fatal(err)
}

envFileKeys[e.Name] = string(b)
Expand Down

0 comments on commit 1b88e69

Please sign in to comment.