Class: Open
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.
-
#page_url ⇒ Object
Returns the URL for the repository page.
- #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.
38 39 40 41 42 43 44 45 |
# File 'lib/git-utils/open.rb', line 38 def cmd if [:print] puts page_url "" else "#{open} #{page_url}" end end |
#page_url ⇒ Object
Returns the URL for the repository page.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/git-utils/open.rb', line 18 def page_url if service == 'stash' && protocol == 'ssh' pattern = /(.*)@([^:]*):?([^\/]*)\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2/projects/\4/repos/\5/browse?at=' + current_branch elsif service == 'stash' && protocol == 'http' pattern = /(.*)@([^:\/]*)(:?[^\/]*)\/(.*)scm\/([^\/]*)\/(.*)\.git/ replacement = 'https://\2\3/\4projects/\5/repos/\6/browse?at=' + current_branch elsif protocol == 'ssh' pattern = /(.*)@(.*):(.*)\.git/ replacement = 'https://\2/\3' elsif protocol == 'http' pattern = /https?\:\/\/(([^@]*)@)?(.*)\.git/ replacement = 'https://\3' end origin_url.sub(pattern, replacement) end |
#parser ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/git-utils/open.rb', line 5 def parser OptionParser.new do |opts| opts. = "Usage: git open" opts.on("-p", "--print", "print URL instead of opening") do |opt| self..print = opt end opts.on_tail("-h", "--help", "this usage guide") do puts opts.to_s; exit 0 end end end |