4bcbdc54c9
This switches the Metasploit Framework to a Rails 3 backend. If you run into new problems (especially around Active Record or your postgresql gem) you should try first updating your Ruby installation to 1.9.3 and use a more recent 'pg' gem. If that fails, we'd love to see your bug report (just drop all the detail you can into an issue on GitHub). In the meantime, you can checkout the rails2 branch, which was branched from master immediately before this cutover. Squashed commit of the following: commit 5802ec851580341c6717dfea529027c12678d35f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 23:30:12 2012 -0500 Enable MSF_BUNDLE_GEMS mode by default (set to N/F/0 to disable) commit 8102f98dce9eb0c73c4374e40dce09af7b51d060 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 23:30:03 2012 -0500 Add a method to expand win32 file paths commit bda6479d154cf75572dd5de8b66bfde661a55de9 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:53:44 2012 -0500 Fix 1.8.x compatibility commit 101ce4eb17bfdf755ef8c0a5198174668b6cd6fd Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:40:59 2012 -0500 Use verbose instead of stringio commit 5db467ffb593488285576d183b1662093e454b3e Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:30:06 2012 -0500 Hide the iconv warning, were stuck with it due to EBCDIC support commit 63b9cb20eb6a61daf4effb4c8d2761c16ff0c4e0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:29:58 2012 -0500 Dont use GEM_HOME by default commit ca49271c22c314a4465fff934334df18c704cbc0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:23:34 2012 -0500 Move Gemfile to root (there be dragons, lets find them) and catch failed bundler loads commit 34af04076a068e9f60c5526045ddbba5fca359fd Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 18:18:29 2012 -0500 Fallback to bundler when not running inside of a installer env commit ed1066a4f3f12fae7d4afc03eb1ab70ffe2f9cf3 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 16:26:55 2012 -0500 Remove a mess of gems that were not actually required commit 21290a73926809e9049a59359449168f740d13d2 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:59:10 2012 -0500 Hack around a gem() call that is well-intentioned but an obstacle in this case commit 8e414a8bfab9641c81088d22f73033be5b37a700 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Apr 15 15:06:08 2012 -0500 Ruby, come on. Ducktype this. Please. Use interpolated strings to get the to_s behavior you don't get with just plussing. commit 0fa92c58750f8f84edbecfaab72cd2da5062743f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:05:42 2012 -0500 Add new eventmachine/thin gems commit 819d5e7d45e0a16741d3852df3ed110b4d7abc44 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 15:01:18 2012 -0500 Purge (reimport in a second) commit ea6f3f6c434537ca15b6c6674e31081e27ce7f86 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:54:42 2012 -0500 Cleanup uncessary .so files (ext vs lib) commit d219330a3cc563e9da9f01fade016c9ed8cda21c Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:53:02 2012 -0500 PG gems built against the older installation environment commit d6e590cfa331ae7b25313ff1471c6148a6b36f3b Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 14:06:35 2012 -0500 Rename to include the version commit a893de222b97ce1222a55324f1811b0262aae2d0 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 13:56:47 2012 -0500 Detect older installation environments and load the arch-lib directories into the search path commit 6444bba0a421921e2ebe2df2323277a586f9736f Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 13:49:25 2012 -0500 Merge in windows gems commit 95efbcfde220917bc7ee08e6083d7b383240d185 Author: Tod Beardsley <todb@metasploit.com> Date: Sun Apr 15 13:49:33 2012 -0500 Report_vuln shouldn't use :include in finder find_or_create_by doesn't take :include as a param. commit c5f99eb87f0874ef7d32fa42828841c9a714b787 Author: David Maloney <DMaloney@rapid7.com> Date: Sun Apr 15 12:44:09 2012 -0500 One more msised Mdm namespace issue commit 2184e2bbc3dd9b0993e8f21d2811a65a0c694d68 Author: David Maloney <DMaloney@rapid7.com> Date: Sun Apr 15 12:33:41 2012 -0500 Fixes some mroe Mdm namespace confusion Fixes #6626 commit 10cee17f391f398bb2be3409137ff7348c7a66ee Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 03:40:44 2012 -0500 Add robots gem (required by webscan) commit 327e674c83850101364c9cca8f8d16da1de3dfb5 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 03:39:05 2012 -0500 Fix missing error checks commit a5a24641866e47e611d7636a3f19ba3b3ed10ac5 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 01:15:37 2012 -0500 Reorder requires and add a method for injecting a new migration path commit 250a5fa5ae8cb05807af022aa4168907772c15f8 Author: HD Moore <hd_moore@rapid7.com> Date: Sun Apr 15 00:56:09 2012 -0500 Remove missing constant (use string) and add gemcache cleaner commit 37ad6063fce0a41dddedb857fa49aa2c4834a508 Merge: d47ee82 |
||
---|---|---|
.. | ||
lib | ||
test | ||
.gitignore | ||
CHANGES.md | ||
LICENSE | ||
README.md | ||
Rakefile | ||
slop.gemspec |
README.md
Slop
Slop is a simple, lightweight option parser with an easy to remember syntax and friendly API.
Note that this is the v2
branch. If you are looking for version 3 of Slop
please check out the master branch.
Installation
Rubygems
gem install slop
GitHub
git clone git://github.com/injekt/slop.git
gem build slop.gemspec
gem install slop-<version>.gem
Usage
# parse assumes ARGV, otherwise you can pass it your own Array
opts = Slop.parse do
on :v, :verbose, 'Enable verbose mode' # A boolean option
on :n, :name=, 'Your name' # This option requires an argument
on :s, :sex, 'Your sex', true # So does this one
on :a, :age, 'Your age', optional: true # This one accepts an optional argument
on '-D', '--debug', 'Enable debug' # The prefixed -'s are optional
end
# if ARGV is `-v --name 'lee jarvis' -s male`
opts.verbose? #=> true
opts.name? #=> true
opts[:name] #=> 'lee jarvis'
opts.age? #=> false
opts[:age] #=> nil
For more information about creating options, see the Creating Options wiki page.
You can also return your options as a Hash
opts.to_hash #=> { :name => 'Lee Jarvis', :verbose => true, :age => nil, :sex => 'male' }
If you want some pretty output for the user to see your options, you can just
send the Slop object to puts
or use the help
method.
puts opts
puts opts.help
Will output something like
-v, --verbose Enable verbose mode
-n, --name Your name
-a, --age Your age
You can also add a banner using the banner
method
opts = Slop.parse do
banner "Usage: foo.rb [options]"
end
Helpful Help
Long form:
Slop.parse do
...
on :h, :help, 'Print this help message', :tail => true do
puts help
exit
end
end
Shortcut:
Slop.new :help => true
# or
Slop.new :help
Parsing
Slop's pretty good at parsing, let's take a look at what it'll extract for you
Slop.parse(:multiple_switches => false) do
on 's', 'server='
on 'p', 'port=', :as => :integer
on 'username=', :matches => /^[a-zA-Z]+$/
on 'password='
end
Now throw some options at it:
-s ftp://foobar.com -p1234 --username=FooBar --password 'hello there'
Here's what we'll get back
{
:server => "ftp://foobar.com",
:port => 1234,
:username => "FooBar",
:password => "hello there"
}
Events
If you'd like to trigger an event when an option is used, you can pass a block to your option. Here's how:
Slop.parse do
on :V, :version, 'Print the version' do
puts 'Version 1.0.0'
exit
end
end
Now when using the --version
option on the command line, the trigger will
be called and its contents executed.
Yielding Non Options
If you pass a block to Slop#parse
, Slop will yield non-options as
they're found, just like
OptionParser
does it.
opts = Slop.new do
on :n, :name, :optional => false
end
opts.parse do |arg|
puts arg
end
# if ARGV is `foo --name Lee bar`
foo
bar
Negative Options
Slop also allows you to prefix --no-
to an option which will force the option
to return a false value.
opts = Slop.parse do
on :v, :verbose, :default => true
end
# with no command line options
opts[:verbose] #=> true
# with `--no-verbose`
opts[:verbose] #=> false
opts.verbose? #=> false
Short Switches
Want to enable multiple switches at once like rsync does? By default Slop will
parse -abc
as the options a
b
and c
and set their values to true. If
you would like to disable this, you can pass multiple_switches => false
to
a new Slop object. In which case Slop will then parse -fbar
as the option
f
with the argument value bar
.
Slop.parse do
on :a, 'First switch'
on :b, 'Second switch'
on :c, 'Third switch'
end
# Using `-ac`
opts[:a] #=> true
opts[:b] #=> false
opts[:c] #=> true
Slop.parse(:multiple_switches => false) do
on :a, 'Some switch', true
end
# Using `ahello`
opts[:a] #=> 'hello'
Lists
You can of course also parse lists into options. Here's how:
opts = Slop.parse do
opt :people, true, :as => Array
end
# ARGV is `--people lee,john,bill`
opts[:people] #=> ['lee', 'john', 'bill']
Slop supports a few styles of list parsing. Check out this wiki page for more info.
Strict Mode
Passing strict => true
to Slop.parse
causes it to raise a Slop::InvalidOptionError
when an invalid option is found (false
by default):
Slop.new(:strict => true).parse(%w/--foo/)
# => Slop::InvalidOptionError: Unknown option -- 'foo'
Features
Check out the following wiki pages for more features:
Woah woah, why you hating on OptionParser?
I'm not, honestly! I love OptionParser. I really do, it's a fantastic library. So why did I build Slop? Well, I find myself using OptionParser to simply gather a bunch of key/value options, usually you would do something like this:
require 'optparse'
things = {}
opt = OptionParser.new do |opt|
opt.on('-n', '--name NAME', 'Your name') do |name|
things[:name] = name
end
opt.on('-a', '--age AGE', 'Your age') do |age|
things[:age] = age.to_i
end
# you get the point
end
opt.parse
things #=> { :name => 'lee', :age => 105 }
Which is all great and stuff, but it can lead to some repetition. The same thing in Slop:
require 'slop'
opts = Slop.parse do
on :n, :name=, 'Your name'
on :a, :age=, 'Your age', :as => :int
end
opts.to_hash #=> { :name => 'lee', :age => 105 }