Giter VIP home page Giter VIP logo

wtc's Introduction

WTC

Actions Status Go Report Card License

WTC is a simple utility you can use to watch files and execute commands.

Install

From master branch
$ 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/

Or just head to the releases page and download the latest version for you platform.

Compile from source

Before you begin, ensure you have installed the latest version of Go. See the Go documentation for details.

$ go get -u github.com/rafaelsq/wtc

Usage

$ wtc --help
USAGE:
wtc [[flags] [regex command]]
        e.g.: wtc
            // will read [.]wtc.y[a]ml
        e.g.: wtc -r -sfmt "_test\.go$" "go test -cover {PKG}"

wtc [flags]] [rule-name]
        e.g.: wtc -t rule-name
             wtc --no-trace "rule ruleb"
             wtc -arg-pkg any/path rule
             wtc -arg-file path/to/file.ext rule
FLAGS:
  -arg-file string
        wtc -arg-file path/to/file rule-name
  -arg-pkg string
        wtc -arg-pkg path/to/folder rule-name
  -debounce int
        global debounce (default 300)
  -f string
        wtc config file (default try to find [.]wtc.y[a]ml)
  -ignore string
        regex
  -ignore-rules string
        ignore one or more rules (e.g.: -ignore-rules "ruleA,ruleB"
                                  or export WTC_IGNORE_RULES=ruleA,ruleB)
  -no-trace
        disable messages.
  -r    run on start
  -sfmt
        simple format(stderr red)
  -t string
        trig one or more rules by name
                e.g.: wtc -t ruleA
                     wtc -t "ruleA ruleB"

Usage with [.]wtc.y[a]ml

You can configure WTC by creating an YAML file with your own rules.

Example with all options:

no_trace: false
debounce: 300  # if rule has no debounce, this will be used instead
ignore: \.git/
kill_signal: 2 # SIGINT (default: 9 SIGKILL)
kill_timeout: 3 # how many seconds we wait for the applicaton to exit before we send SIGKILL(9)
format:
  time: "15:04:05" # golang format
  ok: "\u001b[38;5;244m[{{.Time}}] \u001b[38;5;2m[{{.Title}}]\u001b[0m \u001b[38;5;238m{{.Message}}\u001b[0m\n"
  fail: "\u001b[38;5;244m[{{.Time}}] \u001b[38;5;1m[{{.Title}}] \u001b[38;5;238m{{.Message}}\u001b[0m\n"
  command_ok: "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[0m{{.Message}}\n"
  command_err: "\u001b[38;5;240m[{{.Time}}] [{{.Title}}] \u001b[38;5;1m{{.Message}}\u001b[0m\n"
trig: [start, buildNRun]  # will run start and after buildNRun
trig_async: # will run test and async concurrently
  - test
  - async
env:
  - name: PORT
    value: 2000
  - type: file
    name: ./base.env
rules:
  - name: start
  - name: buildNRun
    match: \.go$
    ignore: _test\.go$
    command: go build
    env:
      - name: ENV
        value: development
      - name: %{BASE_FILE}% # replace from environment
        type: file
    trig: 
      - done build
      - run
      - test
  - name: done build
  - name: run
    command: ./$(basename `pwd`)
  - name: test
    env:
      - name: ENV
        value: test
      - name: %{BASE_FILE}%
        type: file
    match: _test\.go$
    command: go test -cover {PKG}
  - name: async
    command: echo async

Example base.env

export PORT=3000

# will be replaced by the environment variable
ENVIRONMENT=%{ENV}%

You can also trig a rule using wtc -t, example;
wtc -t "start buildNRun"
wtc --no-trace buildNRun

Dev

$ make will watch for changes and run go install or just run $ go run main.go

debounce: 100
ignore: "\\.git/"
trig: install
rules:
  - name: install
    match: "\\.go$"
    command: "go install"

wtc's People

Contributors

bethanyj28 avatar dgupta04 avatar gabrielsimoes avatar guilhermehubner avatar lavarini avatar marco-silveira avatar pedrohb88 avatar rafaelrubbioli avatar rafaelsq avatar rodrigo-brito avatar scottydocs avatar tomerpacific avatar veridiem avatar vinicio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wtc's Issues

Pre compile regexp

Instead of using MustCompile all the time a file change, it must precompile it and re-use the compiled version.

Change wtc arguments

If you run wtc without arguments it will watch for .go files.
If you run wtc with arguments, it will use the first argument as go build command and the second argument as the command to run after the build.
What I want it to use the wtc to watch anything and execute any command.
So I thought about something like this;

Watch files
If you have a .wtc.yaml or wtc.yaml file it will be used instead of the arguments

Usage:
  wtc [flags] regex command

Flags:
  -d, --debounce int      (default 0)
  -i, --ignore string     regex to be used(default None)
  --no_trace              do not show the command being executed(default False)
  -h, --help              show this help
  • wtc --help must show the help above(golang flags)
  • default rules for Golang should be removed.
  • update Readme.md

Implement env

no_trace: false
debounce: 300
ignore: \.git/
trig: [start, buildNRun]
env:
  - name: PORT  # NEW
    value: 2000
rules:
  - name: start
  - name: buildNRun
    match: \.go$
    ignore: _test\.go$
    command: go build
    env:
      - name: development  # NEW
        value: true
    trig: 
      - done build
      - run
      - test
  - name: done build
  - name: run
    command: ./$(basename `pwd`)
  - name: test
    match: _test\.go$
    command: go test -cover {PKG}

Run with -pkg & -file

If you run wtc <rule> it will trigger the rule with the same name, but if this rule use a {PKG} or {FILE} tag, it will fail.
This PR must add an optional -pkg and -file argument to be used in this case.

Argument to ignore rule.trig

Imagine this yaml;

rules:
  - name: hello
    command: echo hello
    trig: [bye]
  - name: bye
    command: echo bye

If you run wtc -no-trace hello, the output will be;

[11:16:48] [hello] hello
[11:16:48] [hello]
[11:16:49] [bye] bye
[11:16:49] [bye]

But sometimes we don't want the bye rule to run, so;

  • add the argument -no-trig
    It must prevent the trig and trig_async to run.
  • update the usage.

Use yaml

if wtc.yaml exists, read config from it.

build: "go build -mod=vendor -o server cmd/server/server.go"
run: "./server"
rules:
  - name: Test
    regex: "_test\.go$"
    ignore: "^vendor/"
    debounce: 500
    command: "go test $PACKAGE"

Change Trig field to list

  • trig field should now be a list of strings
  • update README.md
trig:
    first
rules:
  - name: first
    command: "echo first"
    trig:
        second
        third
  - name: second
    command: "echo second"
  - name: third
    command: "echo third"

Add optional option to change the output color.

Suggestion;
Add the output field to Yaml file.

output:
  success: \033[30;1m[{TIME}] \033[32;1m[{NAME}]\033[0m \033[30;1m{CMD}\033[0m\n
  fail: \033[30;1m[{TIME}] \033[31;1m[{NAME} failed]\033[0m \033[30;1m{ERROR}\033[0m\n

ps; it should be optional

Ignore rule

Example;

rules:
  - name: run
    match: \.go$
    ignore: _test\.go$
    command: go run main.go

  - name: test
    match: _test\.go$
    command: go test ${PKG}

  - name: lint
    match: \.go$
    command: golangci-lint ${FILE}

Add a way to ignore some rules;

  • add --ignore-rules "test, lint"
  • env maybe? something like export WTC_IGNORE_RULE=test,lint

so if a run wtc --ignore-rules "test,lint" and edit a *_test.go, it should not run test and lint.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.