ggem 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +0 -3
- data/ggem.gemspec +3 -3
- data/lib/ggem/cli.rb +45 -50
- data/lib/ggem/cli/clirb.rb +44 -48
- data/lib/ggem/cli/commands.rb +5 -39
- data/lib/ggem/gem.rb +41 -41
- data/lib/ggem/gemspec.rb +65 -70
- data/lib/ggem/git_repo.rb +37 -42
- data/lib/ggem/template.rb +50 -58
- data/lib/ggem/template_file/Gemfile.erb +2 -2
- data/lib/ggem/template_file/README.md.erb +3 -3
- data/lib/ggem/template_file/gemspec.erb +5 -6
- data/lib/ggem/template_file/lib.rb.erb +2 -2
- data/lib/ggem/template_file/lib_version.rb.erb +1 -1
- data/lib/ggem/template_file/ruby-version.erb +1 -1
- data/lib/ggem/template_file/test_support_factory.rb.erb +0 -1
- data/lib/ggem/version.rb +1 -1
- data/log/{.gitkeep → .keep} +0 -0
- data/test/support/cmd_tests_helpers.rb +33 -38
- data/test/support/factory.rb +0 -1
- data/test/support/name_set.rb +53 -59
- data/test/system/ggem_tests.rb +0 -5
- data/test/unit/cli_tests.rb +0 -31
- data/test/unit/gem_tests.rb +0 -4
- data/test/unit/gemspec_tests.rb +1 -8
- data/test/unit/git_repo_tests.rb +1 -12
- metadata +10 -12
- data/lib/ggem/template_file/circleci_config.yml.erb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe73b45d444a8f7ff488f19259fc7a0668c681db033d19f2eb1b221d004edac5
|
4
|
+
data.tar.gz: 5ea32d246eafec3af4fd01f17e6ed94c05c95b4a53a667d8966114cff59d387c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf33a27c2b503dc4d6233a3d6afb05dd34b86d326d19f9202b37aeb82b44cef1e70a901e140eff2a34528699e619f761c84caeabdc5029cb62f40227a026ac0
|
7
|
+
data.tar.gz: 00c64f8c24b4de4f2858994d59ff6b52b62474103e2865709a89bc62e48ae8a0d69b700bd967e669c04dd4b8ce24cda86c2f2c61707411370a97fd17776ba051
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -58,9 +58,6 @@ The `generate` command creates a folder and files for developing, testing, and r
|
|
58
58
|
* adds `TODO` entries in files where user input is needed
|
59
59
|
* source control using [Git](https://git-scm.com/)
|
60
60
|
* test using [Assert](https://github.com/redding/assert)
|
61
|
-
* CI with CircleCI
|
62
|
-
* see `.circleci/config.yml`
|
63
|
-
* need to replace `/todo_org_name` with the gem's org name (ie `/redding`)
|
64
61
|
|
65
62
|
You can also call this command using the `g` alias: `ggem g -h`.
|
66
63
|
|
data/ggem.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.required_ruby_version =
|
21
|
+
gem.required_ruby_version = "~> 2.5"
|
22
22
|
|
23
|
-
gem.add_development_dependency("assert", ["~> 2.
|
23
|
+
gem.add_development_dependency("assert", ["~> 2.18.2"])
|
24
24
|
|
25
|
-
gem.add_dependency("much-plugin", ["~> 0.2.
|
25
|
+
gem.add_dependency("much-plugin", ["~> 0.2.2"])
|
26
26
|
gem.add_dependency("scmd", ["~> 3.0.3"])
|
27
27
|
|
28
28
|
end
|
data/lib/ggem/cli.rb
CHANGED
@@ -2,62 +2,57 @@ require "ggem/version"
|
|
2
2
|
require "ggem/cli/clirb"
|
3
3
|
require "ggem/cli/commands"
|
4
4
|
|
5
|
-
module GGem
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
c.add(ReleaseCommand, "release", "r")
|
16
|
-
end
|
5
|
+
module GGem; end
|
6
|
+
class GGem::CLI
|
7
|
+
COMMANDS = CommandSet.new{ |unknown| InvalidCommand.new(unknown) }.tap do |c|
|
8
|
+
c.add(GenerateCommand, "generate", "g")
|
9
|
+
c.add(BuildCommand, "build", "b")
|
10
|
+
c.add(InstallCommand, "install", "i")
|
11
|
+
c.add(PushCommand, "push", "p")
|
12
|
+
c.add(TagCommand, "tag", "t")
|
13
|
+
c.add(ReleaseCommand, "release", "r")
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def self.run(args)
|
17
|
+
self.new.run(args)
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def initialize(kernel = nil, stdout = nil, stderr = nil)
|
21
|
+
@kernel = kernel || Kernel
|
22
|
+
@stdout = stdout || $stdout
|
23
|
+
@stderr = stderr || $stderr
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
@kernel.exit 0
|
26
|
+
def run(args)
|
27
|
+
begin
|
28
|
+
cmd_name = args.shift
|
29
|
+
cmd = COMMANDS[cmd_name]
|
30
|
+
cmd.run(args)
|
31
|
+
rescue CLIRB::HelpExit
|
32
|
+
@stdout.puts cmd.help
|
33
|
+
rescue CLIRB::VersionExit
|
34
|
+
@stdout.puts GGem::VERSION
|
35
|
+
rescue CLIRB::Error, ArgumentError, InvalidCommandError => exception
|
36
|
+
display_debug(exception)
|
37
|
+
@stderr.puts "#{exception.message}\n\n"
|
38
|
+
@stdout.puts cmd.help
|
39
|
+
@kernel.exit 1
|
40
|
+
rescue CommandExitError
|
41
|
+
@kernel.exit 1
|
42
|
+
rescue StandardError => exception
|
43
|
+
@stderr.puts "#{exception.class}: #{exception.message}"
|
44
|
+
@stderr.puts exception.backtrace.join("\n")
|
45
|
+
@kernel.exit 1
|
50
46
|
end
|
47
|
+
@kernel.exit 0
|
48
|
+
end
|
51
49
|
|
52
|
-
|
50
|
+
private
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
52
|
+
def display_debug(exception)
|
53
|
+
if ENV["DEBUG"]
|
54
|
+
@stderr.puts "#{exception.class}: #{exception.message}"
|
55
|
+
@stderr.puts exception.backtrace.join("\n")
|
59
56
|
end
|
60
|
-
|
61
57
|
end
|
62
|
-
|
63
58
|
end
|
data/lib/ggem/cli/clirb.rb
CHANGED
@@ -1,59 +1,55 @@
|
|
1
1
|
module GGem; end
|
2
|
-
class GGem::CLI
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@opts[o.name] = o.value; p.on(*o.parser_args){ |v| @opts[o.name] = v }
|
15
|
-
end
|
16
|
-
p.on_tail("--version", ""){ |v| raise VersionExit, v.to_s }
|
17
|
-
p.on_tail("--help", ""){ |v| raise HelpExit, v.to_s }
|
2
|
+
class GGem::CLI; end
|
3
|
+
class GGem::CLI::CLIRB # Version 1.1.0, https://github.com/redding/cli.rb
|
4
|
+
Error = Class.new(RuntimeError);
|
5
|
+
HelpExit = Class.new(RuntimeError); VersionExit = Class.new(RuntimeError)
|
6
|
+
attr_reader :argv, :args, :opts, :data
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
@options = []; instance_eval(&block) if block
|
10
|
+
require "optparse"
|
11
|
+
@data, @args, @opts = [], [], {}; @parser = OptionParser.new do |p|
|
12
|
+
p.banner = ""; @options.each do |o|
|
13
|
+
@opts[o.name] = o.value; p.on(*o.parser_args){ |v| @opts[o.name] = v }
|
18
14
|
end
|
15
|
+
p.on_tail("--version", ""){ |v| raise VersionExit, v.to_s }
|
16
|
+
p.on_tail("--help", ""){ |v| raise HelpExit, v.to_s }
|
19
17
|
end
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
class Option
|
34
|
-
attr_reader :name, :opt_name, :desc, :abbrev, :value, :klass, :parser_args
|
20
|
+
def option(*args); @options << Option.new(*args); end
|
21
|
+
def parse!(argv)
|
22
|
+
@args = (argv || []).dup.tap do |args_list|
|
23
|
+
begin; @parser.parse!(args_list)
|
24
|
+
rescue OptionParser::ParseError => err; raise Error, err.message; end
|
25
|
+
end; @data = @args + [@opts]
|
26
|
+
end
|
27
|
+
def to_s; @parser.to_s; end
|
28
|
+
def inspect
|
29
|
+
"#<#{self.class}:#{"0x0%x" % (object_id << 1)} @data=#{@data.inspect}>"
|
30
|
+
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
class Option
|
33
|
+
attr_reader :name, :opt_name, :desc, :abbrev, :value, :klass, :parser_args
|
34
|
+
|
35
|
+
def initialize(name, desc = nil, abbrev: nil, value: nil)
|
36
|
+
@name, @desc = name, desc || ""
|
37
|
+
@opt_name, @abbrev = parse_name_values(name, abbrev)
|
38
|
+
@value, @klass = gvalinfo(value)
|
39
|
+
@parser_args = if [TrueClass, FalseClass, NilClass].include?(@klass)
|
40
|
+
["-#{@abbrev}", "--[no-]#{@opt_name}", @desc]
|
41
|
+
else
|
42
|
+
["-#{@abbrev}", "--#{@opt_name} VALUE", @klass, @desc]
|
45
43
|
end
|
44
|
+
end
|
46
45
|
|
47
|
-
|
46
|
+
private
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
def gvalinfo(v); v.kind_of?(Class) ? [nil,gklass(v)] : [v,gklass(v.class)]; end
|
55
|
-
def gklass(k); k == Fixnum ? Integer : k; end
|
48
|
+
def parse_name_values(name, custom_abbrev)
|
49
|
+
[ (processed_name = name.to_s.strip.downcase).gsub("_", "-"),
|
50
|
+
custom_abbrev || processed_name.gsub(/[^a-z]/, "").chars.first || "a"
|
51
|
+
]
|
56
52
|
end
|
53
|
+
def gvalinfo(v); v.kind_of?(Class) ? [nil,v] : [v,v.class]; end
|
57
54
|
end
|
58
|
-
|
59
55
|
end
|
data/lib/ggem/cli/commands.rb
CHANGED
@@ -3,12 +3,10 @@ require "much-plugin"
|
|
3
3
|
|
4
4
|
module GGem; end
|
5
5
|
class GGem::CLI
|
6
|
-
|
7
6
|
InvalidCommandError = Class.new(ArgumentError)
|
8
7
|
CommandExitError = Class.new(RuntimeError)
|
9
8
|
|
10
9
|
class InvalidCommand
|
11
|
-
|
12
10
|
attr_reader :name, :clirb
|
13
11
|
|
14
12
|
def initialize(name)
|
@@ -30,18 +28,12 @@ class GGem::CLI
|
|
30
28
|
"Commands:\n" \
|
31
29
|
"#{COMMANDS.to_s.split("\n").map{ |l| " #{l}" }.join("\n")}\n"
|
32
30
|
end
|
33
|
-
|
34
31
|
end
|
35
32
|
|
36
33
|
module ValidCommand
|
37
34
|
include MuchPlugin
|
38
35
|
|
39
|
-
|
40
|
-
include InstanceMethods
|
41
|
-
end
|
42
|
-
|
43
|
-
module InstanceMethods
|
44
|
-
|
36
|
+
plugin_instance_methods do
|
45
37
|
def initialize(&clirb_build)
|
46
38
|
@clirb = CLIRB.new(&clirb_build)
|
47
39
|
end
|
@@ -57,20 +49,13 @@ class GGem::CLI
|
|
57
49
|
def summary
|
58
50
|
""
|
59
51
|
end
|
60
|
-
|
61
52
|
end
|
62
|
-
|
63
53
|
end
|
64
54
|
|
65
55
|
module NotifyCmdCommand
|
66
56
|
include MuchPlugin
|
67
57
|
|
68
|
-
|
69
|
-
include InstanceMethods
|
70
|
-
end
|
71
|
-
|
72
|
-
module InstanceMethods
|
73
|
-
|
58
|
+
plugin_instance_methods do
|
74
59
|
private
|
75
60
|
|
76
61
|
def notify(success_msg, &cmd_block)
|
@@ -85,9 +70,7 @@ class GGem::CLI
|
|
85
70
|
@stdout.puts output
|
86
71
|
end
|
87
72
|
end
|
88
|
-
|
89
73
|
end
|
90
|
-
|
91
74
|
end
|
92
75
|
|
93
76
|
module GitRepoCommand
|
@@ -96,10 +79,9 @@ class GGem::CLI
|
|
96
79
|
plugin_included do
|
97
80
|
include ValidCommand
|
98
81
|
include NotifyCmdCommand
|
99
|
-
include InstanceMethods
|
100
82
|
end
|
101
83
|
|
102
|
-
|
84
|
+
plugin_instance_methods do
|
103
85
|
def initialize(*args)
|
104
86
|
super
|
105
87
|
|
@@ -117,7 +99,6 @@ class GGem::CLI
|
|
117
99
|
raise CommandExitError
|
118
100
|
end
|
119
101
|
end
|
120
|
-
|
121
102
|
end
|
122
103
|
end
|
123
104
|
|
@@ -151,7 +132,6 @@ class GGem::CLI
|
|
151
132
|
"Description:\n" \
|
152
133
|
" #{self.summary}"
|
153
134
|
end
|
154
|
-
|
155
135
|
end
|
156
136
|
|
157
137
|
module GemspecCommand
|
@@ -160,10 +140,9 @@ class GGem::CLI
|
|
160
140
|
plugin_included do
|
161
141
|
include ValidCommand
|
162
142
|
include NotifyCmdCommand
|
163
|
-
include InstanceMethods
|
164
143
|
end
|
165
144
|
|
166
|
-
|
145
|
+
plugin_instance_methods do
|
167
146
|
def initialize(*args)
|
168
147
|
super
|
169
148
|
|
@@ -187,7 +166,6 @@ class GGem::CLI
|
|
187
166
|
raise CommandExitError
|
188
167
|
end
|
189
168
|
end
|
190
|
-
|
191
169
|
end
|
192
170
|
end
|
193
171
|
|
@@ -212,7 +190,6 @@ class GGem::CLI
|
|
212
190
|
"Description:\n" \
|
213
191
|
" #{self.summary}"
|
214
192
|
end
|
215
|
-
|
216
193
|
end
|
217
194
|
|
218
195
|
class InstallCommand
|
@@ -242,7 +219,6 @@ class GGem::CLI
|
|
242
219
|
"Description:\n" \
|
243
220
|
" #{self.summary}"
|
244
221
|
end
|
245
|
-
|
246
222
|
end
|
247
223
|
|
248
224
|
class PushCommand
|
@@ -273,7 +249,6 @@ class GGem::CLI
|
|
273
249
|
"Description:\n" \
|
274
250
|
" #{self.summary}"
|
275
251
|
end
|
276
|
-
|
277
252
|
end
|
278
253
|
|
279
254
|
module ForceTagOptionCommand
|
@@ -281,11 +256,9 @@ class GGem::CLI
|
|
281
256
|
|
282
257
|
plugin_included do
|
283
258
|
include ValidCommand
|
284
|
-
include InstanceMethods
|
285
259
|
end
|
286
260
|
|
287
|
-
|
288
|
-
|
261
|
+
plugin_instance_methods do
|
289
262
|
def initialize
|
290
263
|
super do
|
291
264
|
option "force-tag", "force tagging even with uncommitted files", {
|
@@ -293,9 +266,7 @@ class GGem::CLI
|
|
293
266
|
}
|
294
267
|
end
|
295
268
|
end
|
296
|
-
|
297
269
|
end
|
298
|
-
|
299
270
|
end
|
300
271
|
|
301
272
|
class TagCommand
|
@@ -345,7 +316,6 @@ class GGem::CLI
|
|
345
316
|
"Description:\n" \
|
346
317
|
" #{self.summary}"
|
347
318
|
end
|
348
|
-
|
349
319
|
end
|
350
320
|
|
351
321
|
class ReleaseCommand
|
@@ -376,11 +346,9 @@ class GGem::CLI
|
|
376
346
|
" #{self.summary}\n" \
|
377
347
|
" (macro for running `ggem tag && ggem push`)"
|
378
348
|
end
|
379
|
-
|
380
349
|
end
|
381
350
|
|
382
351
|
class CommandSet
|
383
|
-
|
384
352
|
def initialize(&unknown_cmd_block)
|
385
353
|
@lookup = Hash.new{ |h,k| unknown_cmd_block.call(k) }
|
386
354
|
@names = []
|
@@ -425,7 +393,5 @@ class GGem::CLI
|
|
425
393
|
"#{n.ljust(max_name_size)} #{@aliases[n].ljust(max_alias_size)} #{@summaries[n]}"
|
426
394
|
end.join("\n")
|
427
395
|
end
|
428
|
-
|
429
396
|
end
|
430
|
-
|
431
397
|
end
|
data/lib/ggem/gem.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
require "ggem/template"
|
3
3
|
|
4
|
-
module GGem
|
4
|
+
module GGem; end
|
5
|
+
class GGem::Gem
|
6
|
+
NoNameError = Class.new(ArgumentError)
|
5
7
|
|
6
|
-
|
8
|
+
attr_reader :root_path, :name
|
7
9
|
|
8
|
-
|
10
|
+
def initialize(path, name)
|
11
|
+
raise NoNameError if name.to_s.empty?
|
12
|
+
@root_path, self.name = path, name
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
def save!
|
16
|
+
GGem::Template.new(self).save
|
17
|
+
self
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
20
|
+
def path
|
21
|
+
File.join(@root_path, @name)
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
def name=(name)
|
25
|
+
@name = normalize_name(name)
|
26
|
+
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def module_name
|
29
|
+
transforms = {
|
30
|
+
"_" => "",
|
31
|
+
"-" => ""
|
32
|
+
}
|
33
|
+
@module_name ||= transform_name(transforms){ |part| part.capitalize }
|
34
|
+
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
def ruby_name
|
37
|
+
@ruby_name ||= transform_name{ |part| part.downcase }
|
38
|
+
end
|
34
39
|
|
35
|
-
|
40
|
+
private
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def normalize_name(name)
|
43
|
+
und_camelcs = [/([A-Z])([a-z])/, '_\1\2']
|
44
|
+
rm_dup_und = [/_+/, "_"]
|
45
|
+
rm_lead_und = [/^_/, "" ]
|
46
|
+
name.gsub(*und_camelcs).gsub(*rm_dup_und).sub(*rm_lead_und).downcase
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
49
|
+
def transform_name(conditions = {}, &block)
|
50
|
+
n = (block ? block.call(self.name) : self.name)
|
51
|
+
conditions.each do |on, glue|
|
52
|
+
if (a = n.split(on)).size > 1
|
53
|
+
n = a.map{ |part| block.call(part) if block }.join(glue)
|
50
54
|
end
|
51
|
-
n
|
52
55
|
end
|
53
|
-
|
54
|
-
NoNameError = Class.new(ArgumentError)
|
55
|
-
|
56
|
+
n
|
56
57
|
end
|
57
|
-
|
58
58
|
end
|