leitmotif 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76dc265b295f6992a5ae6ad03e73c4353c575997
4
- data.tar.gz: 8eca58e6c899b389ef969c2da5ff3d4f22cd4d33
3
+ metadata.gz: 2d9079e52a65fd270756e1023f9f7dfe037680ea
4
+ data.tar.gz: c9c2670e5ed42f92ae64d7cd09b5884f4015c34f
5
5
  SHA512:
6
- metadata.gz: 612823d2c9c4ae9aa8b406eb3e80828a25c04e6f702f41fef3279937779d0fdf0a54bc5aefa89cd18d74a0b6a7a2949bbd5905477e1158109d1609f149d0b2d4
7
- data.tar.gz: a6138434773482b06ff24ddb20258b9c8f70885fd9d8caff68d24b73e5094c8e9a4aa289f181df2d3a00c142ab0a7dc6ddc25a6b030a2d68a9275f70a78d4dd5
6
+ metadata.gz: aefafc04b2dc8794588184d1058aa927acf822f38e9d2574769c2cf77db585e7f22180d4ecf03ad703bbd2e29d1093847a51e3b01062c5a372e0a27e30bda202
7
+ data.tar.gz: 8147b1152d2ee7868e6fcdcba324fc1ba391a3234c037d94b6edb3ce1a2cba8f0ef67b69b6c96a0033e23aa354a8c6082ca327cc12a61a858201d2f05276ded3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -4,6 +4,13 @@ require "rubygems"
4
4
  require "thor"
5
5
  require "leitmotif" # SKIP_FOR_STANDALONE
6
6
 
7
+ module CLIHelpers
8
+ def symbolize_hash(hash)
9
+ hash.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
10
+ end
11
+ end
12
+
13
+
7
14
  class LeitmotifCLI < Thor
8
15
  desc "generate PROTOTYPE OUTPUT_DIR", "instantiate PROTOTYPE into OUTPUT_DIR"
9
16
  method_option :clobber, :type => :boolean, :desc => "overwrite OUTPUT_DIR if it exists"
@@ -18,7 +25,7 @@ class LeitmotifCLI < Thor
18
25
  puts "prototype is #{prototype}" if $LEITMOTIF_DEBUG
19
26
  puts "output_dir is #{output_dir}" if $LEITMOTIF_DEBUG
20
27
  puts "options are #{options.inspect}" if @LEITMOTIF_DEBUG
21
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
28
+ symbolized_options = symbolize_hash(options)
22
29
  exit(Leitmotif.new(symbolized_options[:bindings], symbolized_options).run(prototype, output_dir))
23
30
  end
24
31
 
@@ -26,19 +33,28 @@ class LeitmotifCLI < Thor
26
33
  method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
27
34
  method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
28
35
  def clone(url)
29
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
30
-
31
- exit(LocalPrototypeStore.new(symbolized_options).cloneProto(url))
36
+ exit(LocalPrototypeStore.new(symbolize_hash(options)).cloneProto(url))
32
37
  end
33
38
 
34
39
  desc "list", "show locally-installed prototypes"
35
40
  method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
36
41
  method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
37
42
  def list()
38
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
39
-
40
- exit(LocalPrototypeStore.new(symbolized_options).list())
43
+ exit(LocalPrototypeStore.new(symbolize_hash(options)).list())
41
44
  end
45
+
46
+ desc "new-prototype NAME", "create a new leitmotif prototype named NAME"
47
+ method_option :local, :type => :boolean, :desc => "create the new prototype in the local store"
48
+ method_option :clobber, :type => :boolean, :desc => "overwrite destination if it exists"
49
+ method_option :edit, :type => :boolean, :desc => "open the new prototype immediately with $EDITOR"
50
+ method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
51
+ method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
52
+ def new_prototype(name)
53
+ exit(PrototypeCreator.new(name, symbolize_hash(options)).create())
54
+ end
55
+
56
+ private
57
+ include CLIHelpers
42
58
  end
43
59
 
44
60
  LeitmotifCLI.start
@@ -102,6 +102,97 @@ module LMPath
102
102
  def self.localPrototypeStore
103
103
  File.join(Dir.home, ".leitmotif-prototypes")
104
104
  end
105
+
106
+ def check_output_dir(outputDir)
107
+ if File.exists?(outputDir)
108
+ if @options[:clobber]
109
+ FileUtils.rm_rf(outputDir)
110
+ else
111
+ raise "#{outputDir} already exists; move it first"
112
+ end
113
+ end
114
+ end
115
+
116
+ def ensure_exists(path)
117
+ unless File.exists?(path)
118
+ FileUtils.mkdir_p(path)
119
+ end
120
+ path
121
+ end
122
+ end
123
+
124
+ class PrototypeCreator
125
+ DEFAULT_OPTIONS = {:git => "/usr/bin/git",
126
+ :verbose => false,
127
+ :debug => false,
128
+ :clobber => false,
129
+ :local => false,
130
+ :edit => false,
131
+ :author => nil,
132
+ :email => nil,
133
+ :commit_message => "Initial revision"}
134
+
135
+ include LMProcessHelpers
136
+ include LMPath
137
+
138
+ def initialize(name, options = nil)
139
+ @options = DEFAULT_OPTIONS.merge(options || {})
140
+ @options[:author] ||= spawn_and_capture(%W{#{@options[:git]} config --global user.name}).strip
141
+ @options[:email] ||= spawn_and_capture(%W{#{@options[:git]} config --global user.email}).strip
142
+ @name = name
143
+
144
+ ensure_exists(LMPath::localPrototypeStore) if @options[:local]
145
+ end
146
+
147
+ def create()
148
+ outputDir = @options[:local] ? File.join(LMPath::localPrototypeStore, @name) : @name
149
+ check_output_dir(outputDir)
150
+ ensure_exists(outputDir)
151
+
152
+ oldcwd = Dir.getwd()
153
+ Dir.chdir(outputDir)
154
+
155
+ begin
156
+ spawn_and_capture(%W{#{@options[:git]} init})
157
+ o,e = spawn_with_input(make_history_file, %W{#{@options[:git]} fast-import})
158
+ puts o if @options[:debug]
159
+ puts e if @options[:debug]
160
+ spawn_and_capture(%W{#{@options[:git]} checkout -b master refs/head/master})
161
+
162
+ exec([ENV["EDITOR"],ENV["EDITOR"]], File.realpath(outputDir)) if @options[:edit]
163
+ ensure
164
+ Dir.chdir(oldcwd)
165
+ end
166
+
167
+ 0
168
+ end
169
+
170
+ private
171
+
172
+ def make_history_file()
173
+ metadata = "---\n:name: #{@name}\n:version: '0'\n:required: []\n:ignore: []\n:defaults: {}\n"
174
+ readme = "This is an empty Leitmotif prototype. For details on how to set it up,\nplease see https://github.com/willb/leitmotif/wiki\n"
175
+ ts = Time.now.strftime('%s %z')
176
+ <<-eos
177
+ blob
178
+ mark :1
179
+ data #{metadata.length}
180
+ blob
181
+ mark :2
182
+ data #{readme.length}
183
+ reset refs/head/master
184
+ commit refs/head/master
185
+ mark :3
186
+ author #{@options[:author]} <#{@options[:email]}> #{ts}
187
+ committer #{@options[:author]} <#{@options[:email]}> #{ts}
188
+ data #{@options[:commit_message].length}
189
+ M 100644 :1 .leitmotif
190
+ M 100644 :2 proto/README
191
+ done
192
+
193
+ eos
194
+ end
195
+
105
196
  end
106
197
 
107
198
  class LocalPrototypeStore
@@ -112,17 +203,16 @@ class LocalPrototypeStore
112
203
  def initialize(options = nil)
113
204
  @options = DEFAULT_OPTIONS.merge(options || {})
114
205
  @localps = LMPath::localPrototypeStore
115
- unless File.exists?(@localps)
116
- FileUtils.mkdir_p(@localps)
117
- end
206
+ ensure_exists(@localps)
118
207
  end
119
208
 
120
209
  include LMProcessHelpers
210
+ include LMPath
121
211
 
122
212
  def cloneProto(remoteURL)
123
213
  begin
124
214
  prototypeName = prototype_name(remoteURL)
125
- spawn_and_capture(%Q{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
215
+ spawn_and_capture(%W{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
126
216
  0
127
217
  rescue Exception=>ex
128
218
  puts "error: #{ex}"
@@ -215,16 +305,6 @@ class Leitmotif
215
305
  0
216
306
  end
217
307
 
218
- def check_output_dir(outputDir)
219
- if File.exists?(outputDir)
220
- if @options[:clobber]
221
- FileUtils.rm_rf(outputDir)
222
- else
223
- raise "#{outputDir} already exists; move it first"
224
- end
225
- end
226
- end
227
-
228
308
  def get_meta_and_proto(remote, treeish = nil)
229
309
  meta = nil
230
310
  proto = nil
@@ -242,22 +322,22 @@ class Leitmotif
242
322
 
243
323
  def get_meta(remote, treeish = nil)
244
324
  treeish ||= @options[:default_treeish]
245
- metaArchive = spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
246
- meta, = spawn_with_input(metaArchive, %Q{#{@options[:tar]} xO .leitmotif})
325
+ metaArchive = spawn_and_capture(%W{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
326
+ meta, = spawn_with_input(metaArchive, %W{#{@options[:tar]} xO .leitmotif})
247
327
  meta
248
328
  end
249
329
 
250
330
  def get_proto(remote, treeish = nil)
251
331
  treeish ||= @options[:default_treeish]
252
- spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
332
+ spawn_and_capture(%W{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
253
333
  end
254
334
 
255
335
  def unpack_proto!(archive)
256
- spawn_with_input(archive, %Q{#{@options[:tar]} x --strip 1})
336
+ spawn_with_input(archive, %W{#{@options[:tar]} x --strip 1})
257
337
  end
258
338
 
259
339
  def list_proto(archive)
260
- out, err = spawn_with_input(archive, %Q{#{@options[:tar]} t})
340
+ out, err = spawn_with_input(archive, %W{#{@options[:tar]} t})
261
341
  out.split("\n")
262
342
  end
263
343
 
@@ -267,6 +347,13 @@ end
267
347
  require "rubygems"
268
348
  require "thor"
269
349
 
350
+ module CLIHelpers
351
+ def symbolize_hash(hash)
352
+ hash.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
353
+ end
354
+ end
355
+
356
+
270
357
  class LeitmotifCLI < Thor
271
358
  desc "generate PROTOTYPE OUTPUT_DIR", "instantiate PROTOTYPE into OUTPUT_DIR"
272
359
  method_option :clobber, :type => :boolean, :desc => "overwrite OUTPUT_DIR if it exists"
@@ -281,7 +368,7 @@ class LeitmotifCLI < Thor
281
368
  puts "prototype is #{prototype}" if $LEITMOTIF_DEBUG
282
369
  puts "output_dir is #{output_dir}" if $LEITMOTIF_DEBUG
283
370
  puts "options are #{options.inspect}" if @LEITMOTIF_DEBUG
284
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
371
+ symbolized_options = symbolize_hash(options)
285
372
  exit(Leitmotif.new(symbolized_options[:bindings], symbolized_options).run(prototype, output_dir))
286
373
  end
287
374
 
@@ -289,19 +376,28 @@ class LeitmotifCLI < Thor
289
376
  method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
290
377
  method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
291
378
  def clone(url)
292
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
293
-
294
- exit(LocalPrototypeStore.new(symbolized_options).cloneProto(url))
379
+ exit(LocalPrototypeStore.new(symbolize_hash(options)).cloneProto(url))
295
380
  end
296
381
 
297
382
  desc "list", "show locally-installed prototypes"
298
383
  method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
299
384
  method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
300
385
  def list()
301
- symbolized_options = options.inject({}){|acc,(k,v)| acc[k.to_sym] = v; acc}
302
-
303
- exit(LocalPrototypeStore.new(symbolized_options).list())
386
+ exit(LocalPrototypeStore.new(symbolize_hash(options)).list())
387
+ end
388
+
389
+ desc "new-prototype NAME", "create a new leitmotif prototype named NAME"
390
+ method_option :local, :type => :boolean, :desc => "create the new prototype in the local store"
391
+ method_option :clobber, :type => :boolean, :desc => "overwrite destination if it exists"
392
+ method_option :edit, :type => :boolean, :desc => "open the new prototype immediately with $EDITOR"
393
+ method_option :verbose, :type => :boolean, :desc => "provide additional debugging output"
394
+ method_option :debug, :type => :boolean, :desc => "provide way too much additional debugging output"
395
+ def new_prototype(name)
396
+ exit(PrototypeCreator.new(name, symbolize_hash(options)).create())
304
397
  end
398
+
399
+ private
400
+ include CLIHelpers
305
401
  end
306
402
 
307
403
  LeitmotifCLI.start
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: leitmotif 0.0.1 ruby lib
5
+ # stub: leitmotif 0.0.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "leitmotif"
9
- s.version = "0.0.1"
9
+ s.version = "0.0.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["William Benton"]
14
- s.date = "2014-10-08"
14
+ s.date = "2014-10-09"
15
15
  s.description = "there are many like it, but this one is mine"
16
16
  s.email = "self@willbenton.com"
17
17
  s.executables = ["leitmotif"]
@@ -42,6 +42,100 @@ module LMPath
42
42
  def self.localPrototypeStore
43
43
  File.join(Dir.home, ".leitmotif-prototypes")
44
44
  end
45
+
46
+ def check_output_dir(outputDir)
47
+ if File.exists?(outputDir)
48
+ if @options[:clobber]
49
+ FileUtils.rm_rf(outputDir)
50
+ else
51
+ raise "#{outputDir} already exists; move it first"
52
+ end
53
+ end
54
+ end
55
+
56
+ def ensure_exists(path)
57
+ unless File.exists?(path)
58
+ FileUtils.mkdir_p(path)
59
+ end
60
+ path
61
+ end
62
+ end
63
+
64
+ class PrototypeCreator
65
+ DEFAULT_OPTIONS = {:git => "/usr/bin/git",
66
+ :verbose => false,
67
+ :debug => false,
68
+ :clobber => false,
69
+ :local => false,
70
+ :edit => false,
71
+ :author => nil,
72
+ :email => nil,
73
+ :commit_message => "Initial revision"}
74
+
75
+ include LMProcessHelpers
76
+ include LMPath
77
+
78
+ def initialize(name, options = nil)
79
+ @options = DEFAULT_OPTIONS.merge(options || {})
80
+ @options[:author] ||= spawn_and_capture(%W{#{@options[:git]} config --global user.name}).strip
81
+ @options[:email] ||= spawn_and_capture(%W{#{@options[:git]} config --global user.email}).strip
82
+ @name = name
83
+
84
+ ensure_exists(LMPath::localPrototypeStore) if @options[:local]
85
+ end
86
+
87
+ def create()
88
+ outputDir = @options[:local] ? File.join(LMPath::localPrototypeStore, @name) : @name
89
+ check_output_dir(outputDir)
90
+ ensure_exists(outputDir)
91
+
92
+ oldcwd = Dir.getwd()
93
+ Dir.chdir(outputDir)
94
+
95
+ begin
96
+ spawn_and_capture(%W{#{@options[:git]} init})
97
+ o,e = spawn_with_input(make_history_file, %W{#{@options[:git]} fast-import})
98
+ puts o if @options[:debug]
99
+ puts e if @options[:debug]
100
+ spawn_and_capture(%W{#{@options[:git]} checkout -b master refs/head/master})
101
+
102
+ exec([ENV["EDITOR"],ENV["EDITOR"]], File.realpath(outputDir)) if @options[:edit]
103
+ ensure
104
+ Dir.chdir(oldcwd)
105
+ end
106
+
107
+ 0
108
+ end
109
+
110
+ private
111
+
112
+ def make_history_file()
113
+ metadata = "---\n:name: #{@name}\n:version: '0'\n:required: []\n:ignore: []\n:defaults: {}\n"
114
+ readme = "This is an empty Leitmotif prototype. For details on how to set it up,\nplease see https://github.com/willb/leitmotif/wiki\n"
115
+ ts = Time.now.strftime('%s %z')
116
+ <<-eos
117
+ blob
118
+ mark :1
119
+ data #{metadata.length}
120
+ #{metadata}
121
+ blob
122
+ mark :2
123
+ data #{readme.length}
124
+ #{readme}
125
+ reset refs/head/master
126
+ commit refs/head/master
127
+ mark :3
128
+ author #{@options[:author]} <#{@options[:email]}> #{ts}
129
+ committer #{@options[:author]} <#{@options[:email]}> #{ts}
130
+ data #{@options[:commit_message].length}
131
+ #{@options[:commit_message]}
132
+ M 100644 :1 .leitmotif
133
+ M 100644 :2 proto/README
134
+ done
135
+
136
+ eos
137
+ end
138
+
45
139
  end
46
140
 
47
141
  class LocalPrototypeStore
@@ -52,17 +146,16 @@ class LocalPrototypeStore
52
146
  def initialize(options = nil)
53
147
  @options = DEFAULT_OPTIONS.merge(options || {})
54
148
  @localps = LMPath::localPrototypeStore
55
- unless File.exists?(@localps)
56
- FileUtils.mkdir_p(@localps)
57
- end
149
+ ensure_exists(@localps)
58
150
  end
59
151
 
60
152
  include LMProcessHelpers
153
+ include LMPath
61
154
 
62
155
  def cloneProto(remoteURL)
63
156
  begin
64
157
  prototypeName = prototype_name(remoteURL)
65
- spawn_and_capture(%Q{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
158
+ spawn_and_capture(%W{#{@options[:git]} clone #{remoteURL} "#{File.join(LMPath::localPrototypeStore, prototypeName)}"})
66
159
  0
67
160
  rescue Exception=>ex
68
161
  puts "error: #{ex}"
@@ -155,16 +248,6 @@ class Leitmotif
155
248
  0
156
249
  end
157
250
 
158
- def check_output_dir(outputDir)
159
- if File.exists?(outputDir)
160
- if @options[:clobber]
161
- FileUtils.rm_rf(outputDir)
162
- else
163
- raise "#{outputDir} already exists; move it first"
164
- end
165
- end
166
- end
167
-
168
251
  def get_meta_and_proto(remote, treeish = nil)
169
252
  meta = nil
170
253
  proto = nil
@@ -182,22 +265,22 @@ class Leitmotif
182
265
 
183
266
  def get_meta(remote, treeish = nil)
184
267
  treeish ||= @options[:default_treeish]
185
- metaArchive = spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
186
- meta, = spawn_with_input(metaArchive, %Q{#{@options[:tar]} xO .leitmotif})
268
+ metaArchive = spawn_and_capture(%W{#{@options[:git]} archive --remote #{remote} #{treeish} .leitmotif})
269
+ meta, = spawn_with_input(metaArchive, %W{#{@options[:tar]} xO .leitmotif})
187
270
  meta
188
271
  end
189
272
 
190
273
  def get_proto(remote, treeish = nil)
191
274
  treeish ||= @options[:default_treeish]
192
- spawn_and_capture(%Q{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
275
+ spawn_and_capture(%W{#{@options[:git]} archive --remote #{remote} #{treeish} proto})
193
276
  end
194
277
 
195
278
  def unpack_proto!(archive)
196
- spawn_with_input(archive, %Q{#{@options[:tar]} x --strip 1})
279
+ spawn_with_input(archive, %W{#{@options[:tar]} x --strip 1})
197
280
  end
198
281
 
199
282
  def list_proto(archive)
200
- out, err = spawn_with_input(archive, %Q{#{@options[:tar]} t})
283
+ out, err = spawn_with_input(archive, %W{#{@options[:tar]} t})
201
284
  out.split("\n")
202
285
  end
203
286
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leitmotif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Benton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-08 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda