bin/poohbear-login
#!/usr/bin/env ruby
require 'highline/import'
require 'base64'
require 'polarbear'
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
def usage
puts 'Commands for login in your code collaborator server.'
exit 0
end
#-----------------------------------------------------------------------------
# ................ A R G U M E N T S .. P R O C E S S I N G .................
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# This hash will hold all of the options parsed from the command-line by
# OptionParser.
# login/logout
# creating a new review (reviewer/observers, title)
# adding diff to an existing review
# cancelling review
# finishing a review
# deleting a review
# open a review in the browser
# get review info such as state by id or by title
#-----------------------------------------------------------------------------
options = {}
optparse = OptionParser.new do |opts|
# Set a banner, displayed at the top of the help screen.
opts.banner = 'Usage: poohbear [options] oldbranch newbranch ...'
# Define the options, and what they do
options[:username] = nil
opts.on('-n', '--username username', 'username') do |l|
options[:username] = l
end
options[:password] = nil
opts.on('-p', '--password PASSWORD', 'password') do |l|
options[:password] = l
end
options[:url] = nil
opts.on('-s', '--url URL', 'url') do |l|
options[:url] = l
end
options[:usage] = nil
opts.on( '-u', '--usage', 'Print one liner about this script' ) do
options[:usage] = true
end
opts.on( '-v', '--verbose', 'Verbose ') do
options[:loglevel] = :info
end
# This displays the help screen, all programs are assumed to have this
# option.
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
#-----------------------------------------------------------------------------
# Parse the command-line. Remember there are two forms of the parse method.
# The 'parse' method simply parses ARGV, while the 'parse!' method parses
# ARGV and removes any options found there, as well as any parameters for the
# the options. What's left is the list of files to resize.
#-----------------------------------------------------------------------------
begin
optparse.parse!
rescue => ex
puts ex.to_s
exit 1
end
usage if options[:usage]
_codecollab = PolarBear::CodeCollab.new
options[:url] = _codecollab.configuration.url if options[:url].nil?
options[:username] = _codecollab.configuration.username if options[:username].nil?
options[:url] = ask('URL: ') if options[:url].nil? || options[:url].empty?
options[:username] = ask('Username: ') if options[:username].nil? || options[:username].empty?
options[:password] = ask('Password: ') { |q| q.echo = '*' } if options[:password].nil?
_codecollab.login("#{options[:url]}", "#{options[:username]}", "\"#{options[:password]}\"")