Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created April 16, 2011 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejarvis/923386 to your computer and use it in GitHub Desktop.
Save leejarvis/923386 to your computer and use it in GitHub Desktop.
require 'slop'
opts = Slop.parse do
banner "ruby app.rb {clean,compile,start} [OPTIONS]"
on :v, 'Display the version of App' do
puts 'Version 1.5!'
exit
end
on :V, :verbose, 'Enable verbose mode'
on_empty do
puts help
end
command :clean do
on :v, 'Enable verbose mode'
on :a, :all, 'Clean all?'
end
command :compile do
banner "ruby app.rb compile [OPTIONS]"
on :d, :dir, 'Out directory', true
on :i, :items, 'Range of items. ex: 1,10', true, :as => Range
on_empty do
puts help
end
end
end
if opts[:compile].items? # check if option is present
p opts[:compile][:items].to_a
end
# Try with the following for ARGV:
# ruby app.rb
# ruby app.rb -v
# ruby app.rb compile
# ruby app.rb compile -i 1,10
# many more ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment