-
-
Save anonymous/39826b9066d4ecaa74a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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