• Stars
    star
    446
  • Rank 97,888 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mruby-cli is a platform to build native command line applications for Linux, Windows, and OS X. It provides the tools necessary for building a standalone binary of your application from any machine. Take advantage of the power of Ruby without the cross-platform dependency headaches that go with it.

mruby CLI

A utility for setting up a CLI with mruby that compiles binaries to Linux, OS X, and Windows.

Prerequisites

You'll need the following installed and in your PATH:

On Mac OS X and Windows, Docker Toolbox is the recommended way to install Docker and docker-compose (does not work on windows).

Building a CLI app

To generate a new mruby CLI, there's a --setup option.

$ mruby-cli --setup <app name>

This will generate a folder <app name> containing a basic skeleton for getting started. Once you're in the folder, you can build all the binaries:

$ docker-compose run compile

You'll be able to find the binaries in the following directories:

  • Linux (64-bit): mruby/build/x86_64-pc-linux-gnu/bin
  • Linux (32-bit): mruby/build/i686-pc-linux-gnu/bin
  • OS X (64-bit): mruby/build/x86_64-apple-darwin14/bin/
  • OS X (32-bit): mruby/build/i386-apple-darwin14/bin
  • Windows (64-bit): mruby/build/x86_64-w64-mingw32/bin/
  • Windows (32-bit): mruby/build/i686-w64-mingw32/bin

You should be able to run the respective binary that's native on your platform. There's a shell service that can be used as well. In the example below, mruby-cli --setup hello_world was run.

$ docker-compose run shell
root@3da278e931fc:/home/mruby/code# mruby/build/host/bin/hello_world
Hello World

On Windows system

When running on a windows system docker-compose run, you need to add the flag -d. For instance, docker-compose run -d compile. If you don't add it, you will got the following error:

[31mERROR
Please pass the -d flag when using `docker-compose run`.

Docker

Each app will be generated with a Dockerfile that inherits a base image.

You can pull the image from docker hub here: https://registry.hub.docker.com/u/hone/mruby-cli/

The Dockerfile for the base image is available on github: https://github.com/hone/mruby-cli-docker

Hello World

Building the canonical hello world example in mruby-cli is quite simple. The two files of note from the generate skeleton are mrblib/hello_world.rb and mrbgem.rake. The CLI hooks into the __main__ method defined here and passes all the arguments as argv.

mrblib/hello_world.rb:

def __main__(argv)
  puts "Hello World"
end

Dependencies

The rubygems equivalent is mrbgems. mgem-list contains a list of mgems you can pull from. By default mruby does not include everything in the kitchen sink like MRI. This means to even get puts, we need to include the mruby-print. The list of core gems can be found here. Adding dependencies is simple, you just need to add a line near the bottom of your mrbgem.rake with the two arguments: name and where it comes from.

mrbgem.rake:

MRuby::Gem::Specification.new('hello_world') do |spec|
  spec.license = 'MIT'
  spec.author  = 'Terence Lee'
  spec.summary = 'Hello World'
  spec.bins    = ['hello_world']

  spec.add_dependency 'mruby-print', :core => 'mruby-print'
  spec.add_dependency 'mruby-mtest', :mgem => 'mruby-test'
end

CLI Architecture

The app is built from two parts a C wrapper in tools/ and a mruby part in mrblib/. The C wrapper is fairly minimal and executes the __main__ method in mruby and instantiates ARGV and passes it to the mruby code. You won't need to touch the C wrapper. The rest of the CLI is written in mruby. You can't have subfolders in mrblib/ but you can have as many files in mrblib/. All these files are precompiled into mruby bytecode The build tool for mruby is written in CRuby (MRI).

Testing

By default, mruby-cli generates two kinds of tests: mtest and bintest.

mtest

These tests are unit tests, are written in mruby, and go in the test/ directory. It uses the mrbgem mruby-mtest. The available methods to be used can be found here. To run the tests, just execute:

$ docker-compose run mtest

bintest

These are integration tests, are written in CRuby (MRI), and go in the bintest/ directory. It tests the status and output of the host binary inside a docker container. To run them just execute:

$ docker-compose run bintest

Examples

  • mruby-cli itself is an app generated by mruby-cli, so you can explore this repo on how to build one.
  • mjruby - replacement for jruby-launcher.
  • mruby-eso-research - an app for managing crafting research in Elder Scrolls Online. It uses YAML as the data store.
  • nhk-easy-cli - a command-line client for reading NHK News Web Easy.
  • mruby-static - a static site generator

mruby-cli Development

Compile the mruby-cli binaries

This app is built as a mruby-cli app. To compile the binaries, you must type

docker-compose run compile

and find the binaries in the appropriate directories (mruby/build/<target>/bin/).

The docker container contains the necessary cross toolchain to compile a binary for each supported target. That's why it is checked before running a rake task if it is run inside a container.

Indeed, just using rake compile will not work out of the box because the main build is designed to compile on a 64-bit Linux host. It could work if you are on a 64-Linux host and you have an cross toolchain equivalent to the one we provide into the docker container.

This means that if you want to add a new rake task my_task, you need to add it to the docker-compose.yml to make it available through docker-compose run my_task.

Create the releases

Just type: docker-compose run release

After this command finishes, you'll see the releases for each target in the releases directory.

Create package

We can package the ad hoc release as deb, rpm, msi, or dmg for the following Linux.

To create all the package, just type

docker-compose run package

More Repositories

1

heroku-sendgrid-stats

A Heroku plugin that displays Sendgrid statistics for your Heroku app
Ruby
77
star
2

heroku-buildpack-jsnes

Heroku Buildpack for Running JSNES
Ruby
18
star
3

git_pivot

Tool that allows you to work with Pivotal Tracker from the command line
Ruby
15
star
4

mruby-cli-docker

docker container for building mruby clis
11
star
5

heroku_colorize_console

Colorize Heroku Console Plugin
Ruby
11
star
6

hammer

CLI tool to help building binaries using Heroku's anvil
Ruby
10
star
7

heroku-replay-ratpack

Heroku Replay Service using Logplex built in JRuby with Ratpack
Ruby
9
star
8

heroku_tab_complete_console

Heroku plugin that provides tab complete support in the console
Ruby
9
star
9

rack-cache-app

Example of using Rack::Cache on Heroku
Ruby
9
star
10

heroku_switch_command

Heroku plugin that switches the default heroku remote, for managing multiple apps.
Ruby
8
star
11

mruby_hello_world_cli

Testbed for playing around with a CLI in mruby
Ruby
7
star
12

herocutter

Gemcutter for heroku plugins
Ruby
7
star
13

rails31_enable_runtime_asset_compilation

Rails 3.1 plugin to enable asset compilation by default during runtime
Ruby
7
star
14

heroku_herocutter

Plugin that provides extra heroku plugin functionality to work with Herocutter
Ruby
7
star
15

mruby-rust-hello-world

mrbgem hello world that uses Rust
Ruby
6
star
16

docker-heroku-ruby-builder

Docker setup for building binaries for Heroku's Ruby Buildpack
Shell
6
star
17

herogems

Heroku Plugins as Gems bro
Ruby
6
star
18

rtomayko

Simple acceptance testing, that skips all the tests after a failing test.
Ruby
6
star
19

school

School Projects from JHU CS Classes
Ruby
5
star
20

bundler-api-replay

Parse http log drains from bundler-api and replay traffic to another app.
Ruby
5
star
21

timber

Logging appender for AWS S3
Ruby
5
star
22

dragncards-mc-plugin

MarvelChampions for DragnCards
Rust
5
star
23

heroku-cli-static

JavaScript
4
star
24

zomg_inbox

Software to allow creating email addresses on the fly
Ruby
4
star
25

rails-31-heroku

Rails 3.1 Sample App
Ruby
4
star
26

wornpath

hone.heroku.com's jekyll blog
CSS
4
star
27

heroku-cli-neon-hello-world

Heroku CLI Plugin example that uses neon
JavaScript
3
star
28

mferuby

build mrbgems with Rust
Ruby
3
star
29

cranny_shelf

Sync PragPub magazines on my nook
Ruby
3
star
30

napkins

Thought collection application (personal wiki)
3
star
31

psp_video_thumbnail

Creates the thumbnail (THM) for a psp video using ffmpeg
Ruby
2
star
32

project_euler_clojure

Project Euler Problems done in Clojure
Clojure
2
star
33

mruby-docopt

Ruby
2
star
34

activerecord_establish_connection_url

Backport of ActiveRecord 3.2's establish_connection via URL as a Rails 3 plugin
Ruby
2
star
35

ember-cli-heroku

ember cli addon for making it easier to deploy on heroku
JavaScript
2
star
36

backup_my_mail

Ruby on Rails application that allows a user to generate a backup of their POP/IMAP email account.
Ruby
2
star
37

dhh-soundboard

JavaScript
2
star
38

heroku-docs

Documentation for Heroku, in the form of a Sinatra app serving markdown text files.
JavaScript
2
star
39

rails3_disable_x_sendfile

Rails 3 plugin to disable sendfile
Ruby
2
star
40

heroku-sendgrid-test-email

Heroku plugin to test sendgrid addon
Ruby
2
star
41

rails238-gmail-smtp-example

Rails 2.3.8 app working on Heroku with GMail SMTP
Ruby
2
star
42

cagpsn

Extension to CAG PSN Site for scheduling / managing profiles and game nights
Ruby
2
star
43

sql-console

Sinatra App for Heroku SQL Console
Ruby
2
star
44

ctags_rakefile_parser

Parses Rakefile intended for C/C++ building for the ctags path, uses CFLAGS constant
Ruby
2
star
45

thread_pool_executor

A Thread Pool Executor based off of Java's http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html
Ruby
2
star
46

express-serve-static-gzip

JavaScript
1
star
47

docker-rust-cross

Docker container for cross compiling rust binaries
1
star
48

heroku-cli-free

A heroku cli plugin to find your apps using free dynos and data
TypeScript
1
star
49

heroku-buildpack-qt-webkit

Heroku Buildpack for Setting up QT with Webkit (mainly qmake)
Shell
1
star
50

text_transform

Text flipper rubygem implemented in Helix
Rust
1
star
51

heroku-buildpack-ruby_bamboo

Ruby
1
star
52

mruby-eso-research

Ruby
1
star
53

heroku-cli-ember-fastboot

Deploying ember fastboot fast on Heroku
JavaScript
1
star
54

heroku-buildpack-mutt

Ruby
1
star
55

hammer-gem

Hammer based script for building rubygems
1
star
56

danger-room

Marvel Champions Random Scenario Generator
JavaScript
1
star
57

docker-heroku-mupdf-builder

Heroku mupdf builder for ActiveStorage PDF preview support
Ruby
1
star
58

inline-buildpack

Inline Buildpack Spike
Rust
1
star
59

dotfiles

My dotfiles
Vim Script
1
star
60

goliath

twitch vod downloader
Ruby
1
star
61

git_subversion_tag

Make a tag on subversion from a git branch
Ruby
1
star
62

HelloAndroid

Hello World, Android App
Java
1
star
63

mruby-heapy

Port of https://github.com/schneems/heapy to mruby-cli.
Ruby
1
star
64

github-contributions

Tool for counting "github contributions"
Rust
1
star
65

heroku-buildpack-noop

Shell
1
star
66

heroku-hive-deploy

Heroku plugin for deploying hive.js
Ruby
1
star
67

node-plus-100

Test Cloud Native Buildpack in Rust
Rust
1
star
68

showoff_herocutter

Presentation on Herocutter
Ruby
1
star
69

rails3-blog-demo

Basic Rails 3 App for Heroku Demo
Ruby
1
star
70

NotepadCodeLab

Notepad Code Lab for Android
Java
1
star
71

libbuildpack.rs

Cloud Native Buildpack Library in Rust
Rust
1
star
72

kafka-docker

Experiments for getting kafka quickly in docker
Shell
1
star
73

the_watch

GitHub Archive Watcher
Rust
1
star
74

heroku-buildpack-print-env

heroku buildpack that prints the ENV during build time
Shell
1
star
75

psp_rss_formatter

format RSS feeds properly for Sony PSP RSS Channel app
Ruby
1
star