class Pullr::CLI
Public Class Methods
new()
click to toggle source
Initializes the Command Line Interface (CLI
).
# File lib/pullr/cli.rb, line 12 def initialize @scm = nil @uri = nil @path = nil @mode = :clone @args = [] end
run()
click to toggle source
Runs the Command Line Interface (CLI
).
# File lib/pullr/cli.rb, line 23 def CLI.run self.new.run(*ARGV) end
Public Instance Methods
run(*args)
click to toggle source
Runs the Command Line Interface (CLI
) with the given arguments.
@param [Array<String>] args
Arguments to run the CLI with.
# File lib/pullr/cli.rb, line 33 def run(*args) optparse(*args) case @mode when :clone @uri ||= @args[0] unless @uri STDERR.puts "pullr: missing the URI argument" exit -1 end repo = RemoteRepository.new( :uri => @uri, :scm => @scm ) repo.pull(@path || @args[1]) when :update repo = LocalRepository.new( :uri => @uri, :path => @path, :scm => @scm ) repo.update end end
Protected Instance Methods
optparse(*args)
click to toggle source
Parses the given arguments.
@param [Array<String>] args
The command-line arguments.
# File lib/pullr/cli.rb, line 70 def optparse(*args) opts = OptionParser.new opts.banner = 'usage: pullr URI [PATH]' opts.on('-S','--scm NAME','Source Code Management to use') do |scm| @scm = scm end opts.on('-U','--uri URI','The URI of the repository') do |uri| @uri = uri end opts.on('-u','--update [PATH]','Update the repository') do |path| @mode = :update @path = (path || Dir.pwd) end begin @args = opts.parse!(args) rescue OptionParser::InvalidOption => e STDERR.puts e.message STDERR.puts opts exit -1 end end