Class: Rgit::Cli

Inherits:
Object
  • Object
show all
Includes:
Rgit
Defined in:
lib/rgit/cli.rb

Constant Summary

Constants included from Rgit

VERSION

Class Method Summary collapse

Class Method Details

.parse(args, rgit = Rgit.new(Configuration.exist? ? Configuration.load : Configuration.create)) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rgit/cli.rb', line 4

def self.parse(args, rgit = Rgit.new(Configuration.exist? ? Configuration.load : Configuration.create))
  OptionParser.new do |opts|
    opts.banner = 'Usage: rgit [options]'
    opts.on('--add-root [PATH]', 'Add a root directory (defaults to pwd).') do |root_path|
      rgit.add_root(root_path.nil? ? Dir.pwd : root_path)
    end
    opts.on('--remove-root [PATH]', 'Remove a root directory (defaults to pwd).') do |root_path|
      rgit.remove_root(root_path.nil? ? Dir.pwd : root_path)
    end
    opts.on('--show-roots', 'Show roots.') do |root_path|
      rgit.print_roots
    end
    opts.on('-p', '--pull', 'Git pull') do
      rgit.pull
    end
    opts.on('-f', '--fetch', 'Git fetch') do
      rgit.fetch
    end
    opts.on('-c', '--checkout BRANCH', 'Git checkout') do |branch|
      rgit.checkout branch
    end
    opts.on('-s', '--status', 'Git status') do
      rgit.status
    end
    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
    end
    opts.on_tail('--version', 'Show version') do
      puts VERSION
    end
  end.parse!(args)
end