Class: Open

Inherits:
Command show all
Defined in:
lib/git-utils/open.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



35
36
37
38
39
# File 'lib/git-utils/open.rb', line 35

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

#page_urlObject

Returns the URL for the repository page.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/git-utils/open.rb', line 15

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

#parserObject



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

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