def self.parse args
options = {}
global = OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium [options]'
opts.on '-v', '--version', 'Show Gemnasium version' do
options[:show_version] = true
end
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
opts.separator ''
opts.separator "Available commands are:\ncreate : Create or update project on Gemnasium\ninstall : Install the necessary config file\npush : Push your dependency files to Gemnasium\nmigrate : Migrate the configuration file\nresolve : Resolve project name to an existing project on Gemnasium\n\nSee `gemnasium COMMAND --help` for more information on a specific command.\n\nWARNING! The gemnasium Rubygem has been deprecated.\nPlease use Gemnasium Toolbelt (https://github.com/gemnasium/toolbelt) instead.\n"
end
subcommands = {
'create' => OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium create [options]'
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
end,
'install' => OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium install [options]'
opts.on '--git', 'Create a post-commit hook to run gemnasium push command if a dependency file has been commited' do
options[:install_git_hook] = true
end
opts.on '--rake', 'Create rake task to run Gemnasium' do
options[:install_rake_task] = true
end
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
end,
'push' => OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium push'
opts.on '-i', '--ignore-branch', 'Push to gemnasium regardless of branch' do
options[:ignore_branch] = true
end
opts.on '-s', '--silence-branch', 'Silently ignore untracked branches' do
options[:silence_branch] = true
end
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
end,
'migrate' => OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium migrate [options]'
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
end,
'resolve' => OptionParser.new do |opts|
opts.banner = 'Usage: gemnasium resolve [options]'
opts.on '-h', '--help', 'Display this message' do
options[:show_help] = true
end
end
}
global.order! args
parser = global
unless (command = args.shift).nil?
raise OptionParser::ParseError unless subcommands.has_key?(command)
subcommands[command].order! args
options[:command] = command
parser = subcommands[command]
end
return options, parser
end