Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a command line utility in Ruby

Tags:

ruby

gem

I'd like to write a small command line utility in ruby and distribute it as a gem. I know that once installed, certain gems like Guard, Sass and Thor can be run by themselves from the command line.

What do I need to specify in my gemspec in order to have a gem available like a binary.

like image 439
James Avatar asked Dec 21 '11 07:12

James


People also ask

How do I run a command-line in Ruby?

Press Ctrl twice to invoke the Run Anything popup. Type the ruby script. rb command and press Enter . If necessary, you can specify the required command-line options and script arguments.

How do you pass command-line arguments in Ruby?

How to Use Command-Line Arguments. In your Ruby programs, you can access any command-line arguments passed by the shell with the ARGV special variable. ARGV is an Array variable which holds, as strings, each argument passed by the shell.

How do I use IRB in Ruby?

To use it, you launch the irb executable and type your Ruby code at the prompt. IRB evaluates the code you type and displays the results. IRB gives you access to all of Ruby's built-in features, as well as any libraries or gems you've installed.


1 Answers

Gem::Specification.new do |s| 
  ...
  s.executable = 'name_of_executable'
  ...
end 

http://docs.rubygems.org/read/chapter/20

like image 89
Michael Kohl Avatar answered Nov 14 '22 21:11

Michael Kohl