Class: Pullr::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/pullr/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Initializes the Command Line Interface (CLI).



12
13
14
15
16
17
18
# File 'lib/pullr/cli.rb', line 12

def initialize
  @scm = nil
  @uri = nil
  @path = nil
  @mode = :clone
  @args = []
end

Class Method Details

.runObject

Runs the Command Line Interface (CLI).



23
24
25
# File 'lib/pullr/cli.rb', line 23

def CLI.run
  self.new.run(*ARGV)
end

Instance Method Details

#optparse(*args) ⇒ Object (protected)

Parses the given arguments.

Parameters:

  • args (Array<String>)

    The command-line arguments.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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

#run(*args) ⇒ Object

Runs the Command Line Interface (CLI) with the given arguments.

Parameters:

  • args (Array<String>)

    Arguments to run the CLI with.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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