mgmt 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mgmt +87 -41
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4e103fcf077abbf15b8784d6c6d47b87db93bf3
4
- data.tar.gz: 0d8b56f06cb0f6a50fea05ed2f820f94768af911
3
+ metadata.gz: 7adf2734177f622d4711cc2a90f26f92898602d5
4
+ data.tar.gz: c7d6a1dd4ff154f9055e9a07c333a1139a13104b
5
5
  SHA512:
6
- metadata.gz: 06823b066d6431ac9aba4ef1e2009e09afc6e119c55349873ef56848cacc1ad7aaff10422b4c98f0689b2f741f9b80b140ba9743ee85945bc2789564e4bc04ab
7
- data.tar.gz: 9ce5bf48a57b8ade6de9d7497b469e71f9477a4bfe0d44f7b93138105a6d4dbe373e691942507fa06eafee03d32418c3d7a50b3cda6adda006068be7205f8de9
6
+ metadata.gz: 919ab5c1cb32720fa26146755f220c451c6f81e8a821e2625394057850594c1e66c7ace1e88fc87ceeb710c29253a21417f44ad3ba87765adc9777751c7e1276
7
+ data.tar.gz: c02e3fd6a966e9215136badabe68d7bff67daf0cadcef858f710d98f7918499262fa315659ee22b1f22e4cda5fc1e62a2caf73a709484517237e6ec9b78a9ec3
data/bin/mgmt CHANGED
@@ -9,7 +9,7 @@ module MGMT
9
9
  DEPSFILE = "Gopherfile"
10
10
  LOCKFILE = "Gopherfile.lock"
11
11
  VENDOR = ".vendor"
12
- VERSION = "0.2.0"
12
+ VERSION = "0.2.1"
13
13
 
14
14
  def xputs(code, msg)
15
15
  code = nil if ENV['TERM'] != "xterm"
@@ -24,57 +24,100 @@ module MGMT
24
24
  end
25
25
 
26
26
  def abort(msg)
27
- xputs "31;1", ">>>> #{msg}"
27
+ xputs "31", ">>> #{msg}"
28
28
  Kernel.exit(1)
29
29
  end
30
30
 
31
+ def read
32
+ abort "#{DEPSFILE} not found" unless File.exist?(DEPSFILE)
33
+
34
+ deps = Deps.parse(DEPSFILE)
35
+ deps.merge! Deps.parse(LOCKFILE) if File.exist?(LOCKFILE)
36
+ deps
37
+ end
38
+
31
39
  def pull(deps)
32
40
  deps.each do |dep|
33
- xputs "33;1", "---> #{dep.name}"
34
- dep.pull!
41
+ MGMT.xputs "33", "### #{dep.name}"
42
+ if dep.pull!
43
+ MGMT.xputs nil, " now at ##{dep.tag}"
44
+ end
35
45
  end
36
46
  end
37
47
 
38
- def read_deps
39
- source = File.exist?(LOCKFILE) ? LOCKFILE : DEPSFILE
40
- abort "#{source} not found" unless File.exist?(source)
41
-
42
- File.read(source).each_line.map {|ln| parse(ln) }.compact
48
+ def lock(deps)
49
+ deps.lock!
50
+ MGMT.xputs "32", "=== #{LOCKFILE} written"
43
51
  end
44
52
 
45
- def write_lockfile(deps)
46
- temp = Tempfile.new LOCKFILE
47
- deps.each {|d| temp.puts d.to_s }
48
- temp.close
49
- FileUtils.mv temp.path, LOCKFILE
50
- xputs "32", "==== #{LOCKFILE} written"
53
+ def exec(*c)
54
+ ENV['GOPATH'] = "#{File.expand_path(VENDOR, ".")}:#{ENV['GOPATH']}"
55
+ Kernel.exec *c
51
56
  end
52
57
 
53
- def parse(line)
54
- line = line.strip
55
- return if line[0] == "#"
58
+ class Deps < Array
59
+
60
+ def self.parse(file)
61
+ deps = []
62
+ File.read(file).each_line do |line|
63
+ deps.push Dep.parse(line)
64
+ end
65
+ new deps.compact
66
+ end
67
+
68
+ def find(name)
69
+ detect {|i| i.name == name }
70
+ end
71
+
72
+ def filter(names)
73
+ self.class.new select {|i| names.include?(i.name) }
74
+ end
75
+
76
+ def reset!
77
+ each do |dep|
78
+ dep.tag = nil
79
+ end
80
+ end
56
81
 
57
- tokens = line.split(/ +/)
58
- return if tokens.empty?
82
+ def merge!(locked)
83
+ each do |dep|
84
+ next if dep.tag
59
85
 
60
- opts = {}
61
- tokens[1..-1].each do |token|
62
- case token[0]
63
- when "!", 33
64
- opts[:repo] = token[1..-1]
65
- when "#", 35
66
- opts[:tag] = token[1..-1]
86
+ match = locked.find(dep.name)
87
+ dep.tag = match.tag if match
67
88
  end
68
89
  end
69
- Dep.new tokens[0], opts
70
- end
71
90
 
72
- def exec(*c)
73
- ENV['GOPATH'] = "#{File.expand_path(VENDOR, ".")}:#{ENV['GOPATH']}"
74
- Kernel.exec *c
91
+ def lock!
92
+ temp = Tempfile.new LOCKFILE
93
+ each {|d| temp.puts d.to_s }
94
+ temp.close
95
+ FileUtils.mv temp.path, LOCKFILE
96
+ end
97
+
75
98
  end
76
99
 
77
100
  class Dep
101
+
102
+ def self.parse(line)
103
+ line = line.strip
104
+ return if line[0] == "#"
105
+
106
+ tokens = line.split(/ +/)
107
+ return if tokens.empty?
108
+
109
+ opts = {}
110
+ tokens[1..-1].each do |token|
111
+ case token[0]
112
+ when "!", 33
113
+ opts[:repo] = token[1..-1]
114
+ when "#", 35
115
+ opts[:tag] = token[1..-1]
116
+ end
117
+ end
118
+ new tokens[0], opts
119
+ end
120
+
78
121
  attr_reader :name, :repo
79
122
  attr_accessor :tag
80
123
 
@@ -89,14 +132,17 @@ module MGMT
89
132
  end
90
133
 
91
134
  def pull!
135
+ skip = false
92
136
  if File.directory?(target)
93
- MGMT.sh "git -C #{target} pull -q origin master"
137
+ skip = @tag && @tag == `git -C #{target} log -n 1 --pretty=format:'%h'`.strip
138
+ MGMT.sh "git -C #{target} pull -q origin master" unless skip
94
139
  else
95
- MGMT.sh "git clone #{@repo} #{target}"
140
+ MGMT.sh "git clone -q #{@repo} #{target}"
96
141
  end
97
142
 
98
143
  @tag ||= `git -C #{target} log -n 1 --pretty=format:'%h'`.strip
99
- MGMT.sh "git -C #{target} reset --hard #{@tag}"
144
+ MGMT.sh "git -C #{target} reset -q --hard #{@tag}" unless skip
145
+ !skip
100
146
  end
101
147
 
102
148
  def to_s
@@ -109,18 +155,18 @@ end
109
155
 
110
156
  case ARGV.shift
111
157
  when "install", nil
112
- deps = MGMT.read_deps
158
+ deps = MGMT.read
113
159
  MGMT.pull(deps)
114
- MGMT.write_lockfile(deps)
160
+ MGMT.lock(deps)
115
161
  when "go"
116
162
  MGMT.exec "go", *ARGV
117
163
  when "update"
118
- deps = MGMT.read_deps
119
- some = deps.select {|d| ARGV.include?(d.name) }
164
+ deps = MGMT.read
165
+ some = deps.filter(ARGV)
120
166
  unless some.empty?
121
- some.each {|d| d.tag = nil }
167
+ some.reset!
122
168
  MGMT.pull(some)
123
- MGMT.write_lockfile(deps)
169
+ MGMT.lock(deps)
124
170
  end
125
171
  when "version"
126
172
  puts MGMT::VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mgmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake