Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created January 26, 2016 17:20
Show Gist options
  • Save anonymous/39826b9066d4ecaa74a6 to your computer and use it in GitHub Desktop.
Save anonymous/39826b9066d4ecaa74a6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'optparse'
global_options = {}
download_options = {}
global = OptionParser.new do |opts|
opts.banner = "Usage: taf [options]"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
global_options[:verbose] = v
end
end
subcommands = {
'download' => OptionParser.new do |opts|
opts.banner = "Usage: taf download [options]"
opts.on("-f", "--force", "Force folder replacement") do |f|
download_options[:forced] = f
end
end
}
p ARGV
global.order!
p ARGV
subcommands[ARGV.shift].order!
p 'Global', global_options
p 'Download', download_options
p ARGV
## Results from running it like: ./script.rb -v --verbose download --force argument
## ["-v", "--verbose", "download", "--force", "argument"]
## ["download", "--force", "argument"]
## "Global"
## {:verbose=>true}
## "Download"
## {:forced=>true}
## ["argument"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment