Coder Social home page Coder Social logo

guardian's Introduction

๐Ÿ’‚ Guardian.cr

Guardian watches over your files and runs assigned tasks.

Guardian

Installation

OS X

brew tap f/guardian
brew install guardian

Arch Linux

Guardian is availabe as a package from the Arch User Repository called guardian-git

From Source

git clone https://github.com/f/guardian.git && cd guardian
crystal build src/guardian.cr --release

Quickstart

Crystal Libs

Guardian works seamless with Crystal Projects. It automatically binds itself to library you use.

$ crystal init lib yourlib
$ cd yourlib
$ guardian --init
Created guardian.yml of ./src/yourlib.cr

Non-Crystal Libs

You can use Guardian for other projects.

$ guardian --init
Created guardian.yml

Usage

$ guardian --init

It will create a guardian.yml file to use by Guardian.

guardian.yml

guardian.yml is a simple YAML file.

Simply it has YAML documents with seperated by --- line and each document has files and run keys.

files key needs a glob pattern, and run is a shell command what to run.

files: ./**/*.cr
run: crystal build ./src/guardian.cr
---
files: ./shard.yml
run: shards install

%file% Variable

Guardian replaces %file% variable in commands with the changed file.

files: ./**/*.txt
run: echo "%file% is changed"

Think you have a hello.txt in your directory, and Guardian will run echo "hello.txt is changed" command when it's changed.

Running Guardian

$ guardian
๐Ÿ’‚ Guardian is on duty!

Contributing

  1. Fork it ( https://github.com/f/guardian/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • f Fatih Kadir Akฤฑn - creator, maintainer

guardian's People

Contributors

cjgajard avatar didactic-drunk avatar diggersheep avatar elorest avatar f avatar f1reflyyyylmao avatar felixbuenemann avatar jadekharats avatar lbarasti avatar marceloboeira avatar mibamur avatar naltun avatar wout avatar ysbaddaden 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

guardian's Issues

Feature request. Rate limit.

I like to run crystal tool format on the files I save but that changes the timestamp which triggers guardian which changes the timestamp so it gets in a loop.

If there was some sort of a delay parameter so that could be prevented it would be really nice.

Keep output clean for readablility.

I love guardian and use it in all my projects to run ameba and specs. But often, the leading > (introduced here) gets in the way. Especially when using Webmock for example:

...
>           You can stub this request with the following snippet:
>           
>           WebMock.stub(:get, "https://apisandbox.packlink.com/v1/shipments/123").
>             to_return(body: "")
>           
>            (WebMock::NetConnectNotAllowedError)
...

Often, I wait for the spec to fail and copy the snippet provided by Webmock, but this always includes the leading >. I think we can leave it out and even reduce the number of spaces.

Another thing that bothers me a bit is the filename marked in red:

image

Red should only be used with failures, so I think :cyan would be much better.

Update Guardian's GitHub description

Guardian watches over your files and run assigned tasks should be changed to Guardian watches over your files and runs assigned tasks, in order to keep the grammar consistent. :)

Crash when removing multiple files that are being watched

Hello,

Thank you for sharing guardian with everybody!

I've encountered a bug when several files that are being watched are removed between run intervals.

Steps to reproduce:

# .guardian.yml

---
files: ./*.txt
run: true

With above file, running guardian and proceed to create 3 empty files:

$ touch foo.txt bar.txt baz.txt

Guardian shows:

+ ./bar.txt
$ true
+ ./foo.txt
$ true
+ ./baz.txt
$ true

However on remove:

$ rm *.txt
- ./bar.txt
$ true
- ./foo.txt
Missing hash key: "./foo.txt" (KeyError)
[4493911] *CallStack::unwind:Array(Pointer(Void)) +87
[4493802] *CallStack#initialize<CallStack>:Array(Pointer(Void)) +10
[4493754] *CallStack::new:CallStack +42
[4605137] *KeyError +33
[4605073] *KeyError::new<String>:KeyError +97
[4681949] *Hash(String, Array(String)) +141
[4681798] *Hash(String, Array(String)) +6
[4634092] *Guardian::Watcher#run_tasks<Guardian::Watcher, String>:Array(String) +60
[4634003] *Guardian::Watcher#watch_changes<Guardian::Watcher>:Hash(String, String) +2675
[4631271] *Guardian::Watcher#start_watching<Guardian::Watcher>:NoReturn +215
[4619773] ???
[4618986] ???
[4455223] ???
[4463305] main +41
[139736944515648] __libc_start_main +240
[4450217] _start +41
[0] ???

I think is related to file key not existing inside @runners at the moment it reached that point.

Now sure how to proceed with the modification, which is why I'm opening an issue and not a pull request ๐Ÿ˜‰

Thank you โค๏ธ โค๏ธ โค๏ธ

Coloring output discards command color information

To reproduce compare crystal spec, crystal build, etc running within and without guardian.

  • Without guardian errors are red, pending has it's own easily skipped color, etc.
  • Within guardian the entire command output is grey and to my impaired vision almost unreadable.

I suggest replacing

output = `#{command}`
output.lines.each do |line|
  puts "  #{line.gsub(/\n$/, "").colorize(:dark_gray)}"
end

With:

system command

system solves another problem with long running commands not showing output until exit with the current code.

[macOS] image not found

After install when i try to run showing this error

dyld: Library not loaded: /usr/local/opt/libyaml/lib/libyaml-0.2.dylib
Referenced from: /usr/local/bin/guardian
Reason: image not found
Abort trap: 6

screen shot 2017-02-21 at 11 56 37 pm

brew installation fails the SHA check

==> Installing f/guardian/guardian
==> Downloading https://github.com/f/guardian/archive/v0.0.5.tar.gz
==> Downloading from https://codeload.github.com/f/guardian/tar.gz/v0.0.5
######################################################################## 100.0%
Error: An exception occurred within a child process:
  ChecksumMismatchError: SHA256 mismatch
Expected: b7fb9f1c1fc0994888b14a1848e73e6aba28ac2b15964b1068f0d47c4a29b027
Actual: dbb1340d31e77cbe9a51243152b58772ba987e17a40d1070e43991b436099f35
Archive: /Users/psionides/Library/Caches/Homebrew/downloads/d7329b8588c11b159427ffadc7fe8234db895c25155c3a1777b2bde21e3c1c68--guardian-0.0.5.tar.gz
To retry an incomplete download, remove the file above.

Same SHA sum if I download manually:

> wget https://github.com/f/guardian/archive/v0.0.5.tar.gz
--2018-12-07 14:06:13--  https://github.com/f/guardian/archive/v0.0.5.tar.gz
Resolving github.com... 140.82.118.4, 140.82.118.3
Connecting to github.com|140.82.118.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/f/guardian/tar.gz/v0.0.5 [following]
--2018-12-07 14:06:14--  https://codeload.github.com/f/guardian/tar.gz/v0.0.5
Resolving codeload.github.com... 192.30.253.120, 192.30.253.121
Connecting to codeload.github.com|192.30.253.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: 'v0.0.5.tar.gz'

v0.0.5.tar.gz                                  [ <=>                                                                                     ]   3.78K  --.-KB/s   in 0.001s

2018-12-07 14:06:14 (7.16 MB/s) - 'v0.0.5.tar.gz' saved [3873]

> shasum -a 256 v0.0.5.tar.gz
dbb1340d31e77cbe9a51243152b58772ba987e17a40d1070e43991b436099f35  v0.0.5.tar.gz

Library not loaded

$ brew tap f/guardian
$ brew install guardian
$ guardian init
dyld: Library not loaded: /usr/local/opt/libpcl/lib/libpcl.1.dylib
  Referenced from: /usr/local/bin/guardian
  Reason: image not found
Trace/BPT trap: 5

Crystal Run

I'd like to use this to run a crystal app, then restart it on file change.

How do I do that...?

files: ./**/*.cr
run: crystal run ./src/myapp.cr

---
files: ./shard.yml
run: crystal deps

This just runs on the first change, then never again, presumably it needs to kill the process, then call run again, any ideas?

Thanks!

processing executable files

Is there any specific reason why executable files have to be excluded from processing by guardian (https://github.com/f/guardian/blob/master/src/guardian/watcher.cr#L57)?

I have a repo with some very simple Crystal programs (tasks for AdventOfCode) that I've all marked executable (with the hashbang line #!/usr/bin/env crystal run) so that I can run them from the command line easily, and now I've installed guardian to see if it make things more convenient, but it took me a while to figure out why it didn't work at all when I told it to watch ./**/*.cr...

CI build

Hey @f. Thanks for the great shard.

Would you mind to enable Travis or any other CI tool for Guardian? At least shards build will help to control the compatibility with Crystal versions.

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.