Class: Switch

Inherits:
Command show all
Defined in:
lib/git-utils/switch.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #known_options, #options, #unknown_options

Instance Method Summary collapse

Methods inherited from Command

#current_branch, #initialize, #origin_url, #parse, #protocol, #run!, run!, #service

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#cmdObject

Returns a command appropriate for executing at the command line



20
21
22
23
24
# File 'lib/git-utils/switch.rb', line 20

def cmd
  c = ["git checkout #{other_branch}"]
  c << argument_string(unknown_options) unless unknown_options.empty?
  c.join("\n")
end

#other_branchObject

Returns the branch to switch to.



15
16
17
# File 'lib/git-utils/switch.rb', line 15

def other_branch
  @other_branch ||= `git branch | grep #{pattern}`.strip
end

#parserObject



5
6
7
8
9
10
11
12
# File 'lib/git-utils/switch.rb', line 5

def parser
  OptionParser.new do |opts|
    opts.banner = "Usage: git switch <pattern>"
    opts.on_tail("-h", "--help", "this usage guide") do
      puts opts.to_s; exit 0
    end
  end
end