gitgem 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/gitgem +51 -0
- data/lib/gitgem/action.rb +106 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2305892da3c64b04eb5307b02b1219209b942265
|
4
|
+
data.tar.gz: 54dc7c5173bd815af26ee0828bca7409ea4b5182
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63f7bd0b3e50589c1ec705a5ae6ab04ffc36f982aca244e128f7810a3f2a988c8021bd851a84540aa410652042d254637781578b3375cab6d085cccbbc9882ce
|
7
|
+
data.tar.gz: f9083c4ee105416c3a4155d7b317477fb687418b2e93a2c8fa8b9ff62a220d019f4231763736ba5e3fedc78782426ea49de3717f14b168d2e6718c9e471abb74
|
data/bin/gitgem
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
$LOAD_PATH.push File.expand_path("../../lib", __FILE__)
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
require 'gitgem/action'
|
9
|
+
|
10
|
+
action = ARGV.shift unless ARGV.first.start_with?("-")
|
11
|
+
|
12
|
+
options = {}
|
13
|
+
option_parser = OptionParser.new do |opts|
|
14
|
+
opts.banner = 'Here is help messages of the command line tool.'
|
15
|
+
|
16
|
+
opts.on('-r REPO', '--repo Repo', 'Specify git repo') do |value|
|
17
|
+
options[:repo] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-a ALIAS', '--alias Alias', 'Make Alias') do |value|
|
21
|
+
options[:alias] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-g GEM', '--gem Gem', 'Install GEM') do |value|
|
25
|
+
argvs = value.split("/")
|
26
|
+
options[:alias] = argvs.shift
|
27
|
+
options[:gem_dir] = argvs.join("/")
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-h', '--help', 'Show this message') { puts opts; exit }
|
31
|
+
opts.on('-v', '--version', 'Show version') { exit }
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
|
35
|
+
case action
|
36
|
+
when 'add'
|
37
|
+
repo = options[:repo]
|
38
|
+
repo_alias = options[:alias]
|
39
|
+
GitGem::Action.add(repo_alias, repo)
|
40
|
+
when 'remove'
|
41
|
+
repo = options[:alias]
|
42
|
+
GitGem::Action.remove(repo)
|
43
|
+
when 'install'
|
44
|
+
repo = options[:alias]
|
45
|
+
gem_dir = options[:gem_dir]
|
46
|
+
GitGem::Action.install(repo, gem_dir)
|
47
|
+
when 'uninstall'
|
48
|
+
repo = options[:alias]
|
49
|
+
gem_dir = options[:gem_dir]
|
50
|
+
GitGem::Action.uninstall(repo, gem_dir)
|
51
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module GitGem
|
8
|
+
module Action
|
9
|
+
class << self
|
10
|
+
def add(repo_alias = nil, repo)
|
11
|
+
repo_alias = repo if repo_alias.nil? || repo_alias.empty?
|
12
|
+
|
13
|
+
abort("Alias could not start with '.'") if repo_alias.start_with?(".")
|
14
|
+
|
15
|
+
should_add = true
|
16
|
+
|
17
|
+
result = read_alias(repo_alias)
|
18
|
+
unless result.nil?
|
19
|
+
puts "#{repo_alias} is already exist: #{result}"
|
20
|
+
printf "replace? (y/n): "
|
21
|
+
input = readline
|
22
|
+
if input.start_with?("y")
|
23
|
+
remove(repo_alias)
|
24
|
+
should_add = true
|
25
|
+
else
|
26
|
+
should_add = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
system("echo #{repo_alias}=#{repo} >> #{alias_path}") if should_add
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove(repo_alias)
|
34
|
+
result = read_alias(repo_alias)
|
35
|
+
FileUtils.rm_rf(File.join(base_dir, repo_alias)) unless result.nil?
|
36
|
+
system("sed -i '' '/#{repo_alias}=/d' #{alias_path}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def install(repo_alias, gem_dir)
|
40
|
+
abort("Please specify alias like alias/gem") if repo_alias.nil? || repo_alias.empty?
|
41
|
+
result = read_alias(repo_alias)
|
42
|
+
abort("Could not find alias named #{repo_alias}, please check again.") if result.nil?
|
43
|
+
repo = result.gsub("#{repo_alias}=", "")
|
44
|
+
|
45
|
+
alias_dir = File.join(base_dir, repo_alias)
|
46
|
+
repo_dir = File.join(alias_dir, File.basename(repo, ".git"))
|
47
|
+
pwd = Dir.pwd
|
48
|
+
|
49
|
+
unless File.exist?(alias_dir)
|
50
|
+
Dir.chdir(base_dir)
|
51
|
+
FileUtils.mkdir_p(alias_dir)
|
52
|
+
Dir.chdir(alias_dir)
|
53
|
+
system("git clone -q #{repo}")
|
54
|
+
end
|
55
|
+
|
56
|
+
Dir.chdir(repo_dir)
|
57
|
+
system("git checkout -- .")
|
58
|
+
system("git pull -q")
|
59
|
+
|
60
|
+
gems = Dir.glob(File.join(gem_dir, "*.gem"))
|
61
|
+
abort("Could not find gem in #{File.join(Dir.pwd, gem_dir)}") if gems.nil? || gems.empty?
|
62
|
+
gems.each do |gem|
|
63
|
+
system("gem install #{gem}")
|
64
|
+
end
|
65
|
+
|
66
|
+
Dir.chdir(pwd)
|
67
|
+
end
|
68
|
+
|
69
|
+
def uninstall(repo_alias, gem_dir)
|
70
|
+
abort("Please specify alias like alias/gem") if repo_alias.nil? || repo_alias.empty?
|
71
|
+
result = read_alias(repo_alias)
|
72
|
+
abort("Could not find alias named #{repo_alias}, please check again.") if result.nil?
|
73
|
+
repo = result.gsub("#{repo_alias}=", "")
|
74
|
+
|
75
|
+
alias_dir = File.join(base_dir, repo_alias)
|
76
|
+
repo_dir = File.join(alias_dir, File.basename(repo, ".git"))
|
77
|
+
|
78
|
+
gems = Dir.glob(File.join(repo_dir, gem_dir, "*.gem"))
|
79
|
+
abort("Could not find gem in #{File.join(repo_dir, gem_dir)}") if gems.nil? || gems.empty?
|
80
|
+
gems.each do |gem|
|
81
|
+
gem_name = File.basename(gem, ".gem").split("-")[0...-1].join("-")
|
82
|
+
system("gem uninstall #{gem_name}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def read_alias(repo_alias)
|
89
|
+
result = `cat #{alias_path} | grep #{repo_alias}=`.chomp
|
90
|
+
return nil if result.nil? || result.empty?
|
91
|
+
result
|
92
|
+
end
|
93
|
+
|
94
|
+
def base_dir
|
95
|
+
File.join(ENV["HOME"], ".gitgem")
|
96
|
+
end
|
97
|
+
|
98
|
+
def alias_path
|
99
|
+
path = File.join(base_dir, "alias")
|
100
|
+
FileUtils.mkdir_p(base_dir)
|
101
|
+
system("touch #{path}") unless File.exist?(path)
|
102
|
+
path
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitgem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- saitjr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Install gem from git repo !
|
14
|
+
email: tangjr.work@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- bin/gitgem
|
20
|
+
- lib/gitgem/action.rb
|
21
|
+
homepage: http://rubygems.org/gems/gitgem
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.6.14
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Install gem from git repo !
|
45
|
+
test_files: []
|