Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Website | Report Issue | Source Code ( )
Executable is to the commandline, what ActiveRecord is the database. You can think of Executable as a COM, a Command-line Object Mapper, just as ActiveRecord is an ORM (Object Relational Mapper). Any class mixing in Executable or subclassing Executable::Command can define a complete command line tool using nothing more than Ruby's standard syntax. No special DSL is required.
CLIs can be built by using a Executable as a mixin, or by subclassing
Executable::Command
. Methods seemlessly handle command-line options.
Writer methods (those ending in '=') correspond to options and query
methods (those ending in '?') modify them to be boolean switches.
For example, here is a simple "Hello, World!" commandline tool.
require 'executable'
class HelloCommand
include Executable
# Say it in uppercase?
def loud=(bool)
@loud = bool
end
#
def loud?
@loud
end
# Show this message.
def help?
cli.show_help
exit
end
alias :h? :help?
# Say hello.
def call(name)
name = name || 'World'
str = "Hello, #{name}!"
str = str.upcase if loud?
puts str
end
end
To make the command available on the command line, add an executable to your project calling the #execute or #run methods.
#!usr/bin/env ruby
require 'hello.rb'
HelloCommand.run
If we named this file hello
, set its execute flag and made it available
on our systems $PATH, then:
$ hello
Hello, World!
$ hello John
Hello, John!
$ hello --loud John
HELLO, JOHN!
Executable can also generate help text for commands.
$ hello --help
USAGE: hello [options]
Say hello.
--loud Say it in uppercase?
--help Show this message
If you look back at the class definition you can see it's pulling
comments from the source to provide descriptions. It pulls the
description for the command itself from the #call
method.
Basic help like this is fine for personal tools, but for public facing
production applications it is desirable to utilize manpages. To this end,
Executable provides Markdown formatted help as well. We can access this,
for example, via HelloCommand.help.markdown
. The idea with this is that
we can save the output to man/hello.ronn
or copy it the top of our bin/
file, edit it to perfection and then use tools such a ronn,
binman or md2man
to generate the manpages. What's particularly cool about Executable,
is that once we have a manpage in the standard man/
location in our project,
the #show_help
method will use it instead of the plain text.
For a more detail example see QED and API documentation.
Install with RubyGems in the usual fashion.
$ gem install executable
Executable is a Rubyworks project. As such we largely use in house tools for development.
QED and Microtest are being used for this project.
Executable is copyrighted open source software.
Copyright (c) 2008 Rubyworks (BSD-2-Clause License)
It can be distributed and modified in accordance with the BSD-2-Clause license.
See LICENSE.txt for details.
FAQs
Unknown package
We found that executable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.