项目作者: Val

项目描述 :
Crystal Run : shebang wrapper for Crystal
高级语言: Crystal
项目地址: git://github.com/Val/crun.git
创建时间: 2018-07-25T22:02:31Z
项目社区:https://github.com/Val/crun

开源协议:Other

下载


Travis-CI Build Status
CircleCI Build Status
Release

crun

Crystal Run : shebang wrapper for Crystal

crun is a tool enabling one to put a “bang line” in the source code of
a Crystal program to run it, or to run such a source code file explicitly.
It was inspired by gorun and created in
an attempt to make experimenting with Crystal more appealing to people
used to Ruby and similar languages which operate most visibly with source
code.

Example

As an example, copy the following content to a file named “hello.cr” (or
“hello”, if you prefer):

  1. #!/usr/bin/env crun
  2. puts "Hello world"

Then, simply run it:

  1. $ chmod +x hello.cr
  2. $ ./hello.cr
  3. Hello world!

Features

crun will:

  • write files under a safe directory in $CRUN_CACHE_PATH,
    $XDG_CACHE_HOME/crun, ~/.cache/crun, ~/.cache/.crun or .crun
    in this order, so that the actual script location isn’t touched
    (may be read-only)
  • avoid races between parallel compilation of the same file
  • automatically clean up old compiled files that remain unused for
    some time, by default each 7 days but can be overriden by setting
    CLEAN_CACHE_DAYS
  • replace the process rather than using a child
  • pass arguments to the compiled application properly
  • handle well shards with comment containing dependencies of a
    classical shards.yml file. Anchors used can be changed by settings
    CRUN_SHARDS_START_ANCHOR (default: ---) and
    CRUN_SHARD_END_ANCHOR (default: ...).

Shards support example

  1. #!/usr/bin/env crun
  2. # ---
  3. # minitest:
  4. # github: ysbaddaden/minitest.cr
  5. # ...
  6. class Foo
  7. def bar
  8. "baz"
  9. end
  10. end
  11. require "minitest/autorun"
  12. class FooTest < Minitest::Test
  13. def foo
  14. @foo ||= Foo.new
  15. end
  16. def test_that_foo_bar_baz
  17. assert_equal "baz", foo.bar
  18. end
  19. end
  20. describe Foo do
  21. let(:foo) { Foo.new }
  22. describe "when asked about bar" do
  23. it "must respond baz" do
  24. foo.bar.must_equal("baz")
  25. end
  26. end
  27. end

Where are the compiled files kept?

They are kept under $CRUN_CACHE_PATH, $XDG_CACHE_HOME/crun,
~/.cache/crun, ~/.cache/.crun or .crun in this order, in a directory
named after the hostname and the slug of the source file name.

You can remove these files, but there’s no reason to do this. These
compiled files will be garbage collected by crun itself after a while
once they stop being used. This is done in a fast and safe way so that
concurrently executing scripts will not fail to execute.

How to build and install crun from source

  1. make release
  2. make install

You can change PREFIX or BINDIR environment variable, see Makefile

Usage

  1. usage: crun <source file> [...]

Add Linux binfmt support

  1. echo ':crystal:E::cr::/usr/local/bin/crun:OC' \
  2. | sudo tee /proc/sys/fs/binfmt_misc/register

or

  1. make binfmt

Development

Install Git pre-commit hook

  1. make githook

Makefile help

  1. > make
  2. targets:
  3. auto Run tests suite continuously on writes
  4. binfmt Add Linux binfmt support
  5. check Run Ameba static code check
  6. clean Remove crun builded binary
  7. clobber Clean and remove editor backup files (*~)
  8. crun Build crun binary
  9. format Run Crystal format tool
  10. githook Install Git pre-commit hook
  11. help Show this help
  12. install Install crun binary
  13. release Build crun binary
  14. spec Run crun specs
  15. tests Run tests suite
  16. todo Show fixme and todo comments
  17. uninstall Uninstall crun binary

OsX (for fancy autotests / continuous testing)

  1. brew tap veelenga/tap
  2. brew install ameba crystal fswatch imagemagick terminal-notifier

or

  1. make osx

Debian/Ubuntu (for fancy autotests / continuous testing)

  1. apt install -y -q inotify-tools libnotify-bin

Contributing

  1. Fork it (https://github.com/Val/crun/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

  • Val Laurent Vallar - creator, maintainer
  • bew Benoit de Chezelles