Class: Switch
Instance Attribute Summary
Attributes inherited from Command
#args, #known_options, #options, #unknown_options
Instance Method Summary collapse
-
#cmd ⇒ Object
Returns a command appropriate for executing at the command line.
-
#other_branch ⇒ Object
Returns the branch to switch to.
- #parser ⇒ Object
Methods inherited from Command
#current_branch, #default_branch, #initialize, #origin_url, #parse, #protocol, run!, #run!, #service
Constructor Details
This class inherits a constructor from Command
Instance Method Details
#cmd ⇒ Object
Returns a command appropriate for executing at the command line.
21 22 23 |
# File 'lib/git-utils/switch.rb', line 21 def cmd "git checkout #{other_branch}" end |
#other_branch ⇒ Object
Returns the branch to switch to. When multiple branches match, switch to the first one.
16 17 18 |
# File 'lib/git-utils/switch.rb', line 16 def other_branch @other_branch ||= `git branch | grep #{pattern}`.split.first end |
#parser ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/git-utils/switch.rb', line 5 def parser OptionParser.new do |opts| opts. = "Usage: git switch <pattern>" opts.on_tail("-h", "--help", "this usage guide") do puts opts.to_s; exit 0 end end end |