Class: Gpr::CLI
Instance Method Summary collapse
- #fetch(remote = 'origin', branch = nil) ⇒ Object
- #get(param) ⇒ Object
- #list ⇒ Object
- #search(string) ⇒ Object
- #status ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
Methods included from TableBuilder
Instance Method Details
#fetch(remote = 'origin', branch = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gpr/cli.rb', line 89 def fetch(remote = 'origin', branch = nil) repositories = get_repositories repositories.each do |repository| repo_info = parse_repository(repository) puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}" GitHelper.fetch(repository, remote, branch) end end |
#get(param) ⇒ Object
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/gpr/cli.rb', line 7 def get(param) case param when /.+(\/\/|@)(.+)\.git$/ host, user, repository = param.match(/.+(\/\/|@)(.+)\.git$/)[2].split(/(:|\/)/).delete_if.with_index { |_c, index| index.odd? } path = "#{APP_PATH}/#{host}/#{user}/#{repository}" if Dir.exist?(path) puts "#{user}/#{repository} is already registered." return end puts "#{user}/#{repository} is registering..." unless GitHelper.clone(param, path) puts "Failed to clone #{user}/#{repository}." return end add_file(path) when /^([^\/]+)\/([^\/]+)$/ parsed_param = param.match(/^([^\/]+)\/([^\/]+)$/) host = parsed_param[1] user = parsed_param[2] APIHelper.get_repository_urls(host, user).each do |clone_url| get(clone_url) end end end |
#list ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gpr/cli.rb', line 39 def list repositories = get_repositories if [:paths] repositories.each do |repository| puts repository end else repositories.each do |repository| repo_info = parse_repository(repository) puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}" end end end |
#search(string) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gpr/cli.rb', line 59 def search(string) result = Groonga['Files'].select do |record| record.body =~ string end result.each do |record| next unless FileTest.exist?(record._key) next unless /#{options[:file]}/ =~ record.filename if [:file] next unless [:host] == record.host if [:host] next unless [:repository] == record.repository if [:repository] relative_path = record._key.sub(/#{APP_PATH}\/#{record.host}\/#{record.repository}\//, '') puts "#{record.host.color(:yellow)} - #{record.repository.color(:blue)} : #{relative_path.color(:red)}" end end |
#status ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/gpr/cli.rb', line 101 def status repositories = get_repositories table do row do column('REPOSITORY NAME'.style(:bold), 15) column('BRANCH STATUS'.style(:bold), 40) column('DIRECTORY STATUS'.style(:bold), 25) end repositories.each do |repository| row do column(repository.match(/.+\/(.+)/)[1]) column(GitHelper.status(repository)[:branch]) column(GitHelper.status(repository)[:directory]) end end end end |
#update ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gpr/cli.rb', line 77 def update puts 'Updating...' Groonga['Files'].truncate repositories = get_repositories repositories.each do |repository| add_file(repository) end end |
#version ⇒ Object
121 122 123 |
# File 'lib/gpr/cli.rb', line 121 def version puts "gpr #{Gpr::VERSION}" end |