Code Monkey home page Code Monkey logo

runx's Introduction

runx

Cross-platform, zero-install, Ruby-based task runner.

runx enables you to script command-line-friendly tasks in Ruby that you can run across platforms without requiring a Ruby installation.

Setup

Download the zero-install binary to a directory on your PATH.

Usage

Create a Runfile or Runfile.rb with your tasks:

doc 'Start server.'
run :up do
  system 'docker-compose -f services.yml -f env.yml up --build'
end

doc 'Stop server.'
run :down do
  system 'docker-compose -f services.yml -f env.yml down'
end

doc 'Create database migration.'
run 'migrate:make' do |*args|
  system *%w(docker-compose -f services.yml -f env.yml exec app php /src/artisan migrate:make) + args
end

Run runx to see available tasks:

$ runx
[runx] In /Users/schmich.

Tasks:
  up                Start server.
  down              Stop server.
  migrate:make      Create database migration.

Run runx <task> to run a task:

$ runx up
[runx] In /Users/schmich.
Building app
Step 1 : FROM php:7-fpm-alpine
 ---> a0955c912431
...

$ runx migrate:make create_some_table
[runx] In /Users/schmich/test.
Created Migration: 2016_10_06_133147_create_some_table
Generating optimized class loader

Advanced

The bundled Ruby version is 2.1.5.

Command-line arguments are passed to the task block:

run :show do |*args|
  p args
end
$ runx show abc 123 "quoted arg"
[runx] In /Users/schmich.
["abc", "123", "quoted arg"]

A task can be marked as auto to automatically run when no task is specified:

run :baz do
  puts 'Baz task.'
end

auto
run :quux do
  puts 'Quux task.'
end
$ runx
[runx] In /Users/schmich.
Quux task.

When locating the Runfile, directories are searched up to the filesystem root until it's found, so you can invoke runx in project subdirectories.

By default, the working directory is set to the Runfile directory unless the dir attribute is used. dir :pwd sets the working directory to the directory where runx was invoked:

dir :pwd
run :json do |file|
  require 'json'
  puts JSON.pretty_generate(JSON.parse(File.read(file)))
end

You can run tasks from other tasks:

run :add do |x, y|
  puts x.to_i + y.to_i
end

run :add5 do |x|
  run :add, 5, x
end
$ runx add 10 20
[runx] In /Users/schmich.
30

$ runx add5 10
[runx] In /Users/schmich.
15

How It Works

The Go-built runx binary contains an OS-specific version of Phusion's Traveling Ruby runtime, embedded with Jim Teeuwen's go-bindata. At runtime, the Ruby distribution is extracted to ~/.runx/<hash>, the runx binary spawns ruby, which then loads the runx Ruby library, which finally loads the Runfile and runs tasks.

License

Copyright © 2016 Chris Schmich
MIT License. See LICENSE for details.

runx's People

Contributors

schmich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lsl you54f

runx's Issues

runx help or --help should show usage

  • If user has not defined help or --help, then they should show the task list output just like runx by itself
  • If help or --help are user defined, run those instead

Support namespacing, task separation

e.g. runx docker up invokes up task in docker namespace (or docker:up task). Also runnable as runx docker:up

Group commands by namespace in --help output.

Use embedded hash when deploying Ruby runtime

  • We currently hash the executable binary when deploying the Ruby runtime
  • To improve startup speed, we can just embed the bindata.go hash (computed at build time) in the runtime and use that when deploying

Support dir directive on tasks to set the working directory

  • Some tasks need to operate in the current working directory, not the directory containing the Runfile
  • Add a dir directive to tasks to set the directory
  • dir '../foo' sets the directory relative to the Runfile directory
  • dir :pwd sets the directory to the current working directory
  • By default, dir '.' is implied (the Runfile directory)
  • Update "In ..." display
  • Handle non-existent relative directories

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.