sprout 1.1.3.pre → 1.1.4.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/lib/sprout/daemon.rb +1 -0
- data/lib/sprout/executable/boolean.rb +8 -3
- data/lib/sprout/executable/param.rb +5 -1
- data/lib/sprout/generator/command.rb +2 -2
- data/lib/sprout/generator/directory_manifest.rb +4 -4
- data/lib/sprout/generator/file_manifest.rb +22 -7
- data/lib/sprout/generator/template_manifest.rb +1 -2
- data/test/fixtures/examples/echo_inputs.rb +4 -0
- data/test/fixtures/executable/flex3sdk_gem/fdb.bat +4 -0
- data/test/unit/boolean_param_test.rb +6 -1
- data/test/unit/daemon_test.rb +1 -1
- data/test/unit/executable_option_parser_test.rb +12 -0
- data/test/unit/generator_test.rb +25 -1
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.4.pre
|
data/lib/sprout/daemon.rb
CHANGED
@@ -58,11 +58,16 @@ module Sprout
|
|
58
58
|
@hidden_value = true
|
59
59
|
end
|
60
60
|
|
61
|
+
def default_option_parser_declaration
|
62
|
+
return [prefix, '[no-]', option_parser_name] if default == true
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
61
66
|
##
|
62
|
-
# Convert string representations of
|
63
|
-
# to something more
|
67
|
+
# Convert string representations of falsiness
|
68
|
+
# to something more Booleaney.
|
64
69
|
def value=(value)
|
65
|
-
value = (value == "
|
70
|
+
value = (value == "false" || value == false) ? false : true
|
66
71
|
super value
|
67
72
|
end
|
68
73
|
|
@@ -318,7 +318,7 @@ module Sprout
|
|
318
318
|
# How this parameter is provided to the
|
319
319
|
# Ruby OptionParser when being exposed as a Ruby Executable.
|
320
320
|
def option_parser_declaration
|
321
|
-
declaration =
|
321
|
+
declaration = default_option_parser_declaration
|
322
322
|
# TODO: Need to figure out how to support hidden name inputs...
|
323
323
|
#if(hidden_name?)
|
324
324
|
#declaration = [option_parser_type_output]
|
@@ -329,6 +329,10 @@ module Sprout
|
|
329
329
|
declaration.join('')
|
330
330
|
end
|
331
331
|
|
332
|
+
def default_option_parser_declaration
|
333
|
+
[ prefix, option_parser_name ]
|
334
|
+
end
|
335
|
+
|
332
336
|
##
|
333
337
|
# The Ruby OptionParser short name with prefix.
|
334
338
|
def option_parser_short_name
|
@@ -34,7 +34,7 @@ module Sprout::Generator
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def file path, template=nil
|
37
|
-
raise
|
37
|
+
raise Sprout::Errors::GeneratorError.new "Cannot create file with nil path" if path.nil?
|
38
38
|
manifest = FileManifest.new
|
39
39
|
manifest.generator = @generator
|
40
40
|
manifest.path = File.join( working_dir.path, path )
|
@@ -44,7 +44,7 @@ module Sprout::Generator
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def generator name, options={}
|
47
|
-
raise
|
47
|
+
raise Sprout::Errors::GeneratorError.new "Cannot call another generator with nil name" if name.nil?
|
48
48
|
instance = Sprout::Generator.create_instance name, options
|
49
49
|
instance.logger = logger
|
50
50
|
instance.path = working_dir.path
|
@@ -12,9 +12,9 @@ module Sprout::Generator
|
|
12
12
|
def create
|
13
13
|
if !File.directory?(path)
|
14
14
|
FileUtils.mkdir_p path
|
15
|
-
|
15
|
+
say "Created directory: #{path}"
|
16
16
|
else
|
17
|
-
|
17
|
+
say "Skipped directory: #{path}" unless(path == Dir.pwd)
|
18
18
|
end
|
19
19
|
create_children
|
20
20
|
execute_generators
|
@@ -26,10 +26,10 @@ module Sprout::Generator
|
|
26
26
|
|
27
27
|
if success && can_remove?
|
28
28
|
FileUtils.rmdir path
|
29
|
-
say "Removed directory:
|
29
|
+
say "Removed directory: #{path}"
|
30
30
|
true
|
31
31
|
else
|
32
|
-
say "Skipped remove directory:
|
32
|
+
say "Skipped remove directory: #{path}"
|
33
33
|
false
|
34
34
|
end
|
35
35
|
end
|
@@ -6,12 +6,21 @@ module Sprout::Generator
|
|
6
6
|
|
7
7
|
def create
|
8
8
|
content = resolve_template
|
9
|
-
|
10
|
-
File.
|
11
|
-
|
9
|
+
|
10
|
+
if File.exists?(path)
|
11
|
+
if generator.force
|
12
|
+
write_file path, content
|
13
|
+
say "Replaced file: #{path}"
|
14
|
+
true
|
15
|
+
else
|
16
|
+
say "Skipped file: #{path}"
|
17
|
+
false
|
18
|
+
end
|
19
|
+
else
|
20
|
+
write_file path, content
|
21
|
+
say "Created file: #{path}"
|
22
|
+
true
|
12
23
|
end
|
13
|
-
say "Created file: #{path}"
|
14
|
-
true
|
15
24
|
end
|
16
25
|
|
17
26
|
def destroy
|
@@ -23,16 +32,22 @@ module Sprout::Generator
|
|
23
32
|
actual_content = File.read path
|
24
33
|
if generator.force || actual_content == expected_content
|
25
34
|
FileUtils.rm path
|
26
|
-
say "Removed file:
|
35
|
+
say "Removed file: #{path}"
|
27
36
|
true
|
28
37
|
else
|
29
|
-
say "Skipped remove file:
|
38
|
+
say "Skipped remove file: #{path}"
|
30
39
|
false
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
43
|
protected
|
35
44
|
|
45
|
+
def write_file path, content
|
46
|
+
File.open path, 'w+' do |file|
|
47
|
+
file.write content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
def resolve_template
|
37
52
|
read_source
|
38
53
|
end
|
@@ -14,6 +14,10 @@ class EchoInputs < Sprout::Executable::Base
|
|
14
14
|
#
|
15
15
|
add_param :truthy, Boolean
|
16
16
|
|
17
|
+
add_param :long_truthy, Boolean
|
18
|
+
|
19
|
+
add_param :default_truthy, Boolean, { :default => true }
|
20
|
+
|
17
21
|
##
|
18
22
|
# A boolean parameter that defaults to true, and must be
|
19
23
|
# explicitly set to false in order to turn it off.
|
@@ -30,7 +30,12 @@ class BooleanParamTest < Test::Unit::TestCase
|
|
30
30
|
@param.show_on_false = true
|
31
31
|
@param.default = true
|
32
32
|
@param.hidden_value = false
|
33
|
-
assert_equal "--foo [BOOL]", @param.option_parser_declaration
|
33
|
+
assert_equal "--[no-]foo [BOOL]", @param.option_parser_declaration
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not insert [no] param modifier unless default true" do
|
37
|
+
@param.name = 'something_off'
|
38
|
+
assert_equal "--something-off", @param.option_parser_declaration
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
data/test/unit/daemon_test.rb
CHANGED
@@ -61,7 +61,7 @@ class DaemonTest < Test::Unit::TestCase
|
|
61
61
|
@fdb.quit
|
62
62
|
@fdb.wait # wait for actions to finish.
|
63
63
|
|
64
|
-
|
64
|
+
assert_matches /This is an error!/, Sprout.stderr.read
|
65
65
|
end
|
66
66
|
|
67
67
|
should "execute from rake task" do
|
@@ -28,6 +28,18 @@ class ExecutableOptionParserTest < Test::Unit::TestCase
|
|
28
28
|
@exe.parse! [ '--truthy', @default_input ]
|
29
29
|
assert @exe.truthy
|
30
30
|
end
|
31
|
+
|
32
|
+
should "accept long boolean with hidden_value" do
|
33
|
+
assert !@exe.long_truthy
|
34
|
+
@exe.parse! [ '--long-truthy', @default_input ]
|
35
|
+
assert @exe.long_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
should "accept negative truthy" do
|
39
|
+
assert @exe.default_truthy, "Should default true"
|
40
|
+
@exe.parse! [ '--no-default-truthy', @default_input ]
|
41
|
+
assert !@exe.default_truthy, "Should accept no- prefix"
|
42
|
+
end
|
31
43
|
|
32
44
|
should "always accept help option" do
|
33
45
|
@exe.expects :puts
|
data/test/unit/generator_test.rb
CHANGED
@@ -58,6 +58,29 @@ class GeneratorTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
should "not clobber existing files" do
|
62
|
+
dir = File.join(@fixture, 'some_project', 'src')
|
63
|
+
FileUtils.mkdir_p dir
|
64
|
+
File.open File.join(dir, 'SomeProject.as'), 'w+' do |f|
|
65
|
+
f.write "Hello World"
|
66
|
+
end
|
67
|
+
@generator.input = 'some_project'
|
68
|
+
@generator.execute
|
69
|
+
assert_matches /Hello World/, File.read(File.join(dir, 'SomeProject.as'))
|
70
|
+
end
|
71
|
+
|
72
|
+
should "clobber existing files if --force" do
|
73
|
+
dir = File.join(@fixture, 'some_project', 'src')
|
74
|
+
FileUtils.mkdir_p dir
|
75
|
+
File.open File.join(dir, 'SomeProject.as'), 'w+' do |f|
|
76
|
+
f.write "Hello World"
|
77
|
+
end
|
78
|
+
@generator.input = 'some_project'
|
79
|
+
@generator.force = true
|
80
|
+
@generator.execute
|
81
|
+
assert_matches /public function SomeProject/, File.read(File.join(dir, 'SomeProject.as'))
|
82
|
+
end
|
83
|
+
|
61
84
|
should "call another generator" do
|
62
85
|
@generator.external = true
|
63
86
|
@generator.execute
|
@@ -78,6 +101,7 @@ class GeneratorTest < Test::Unit::TestCase
|
|
78
101
|
should "respect updates from subclasses" do
|
79
102
|
@generator = configure_generator SubclassedGenerator.new
|
80
103
|
@generator.input = 'some_project'
|
104
|
+
@generator.force = true
|
81
105
|
@generator.execute
|
82
106
|
assert_file File.join(@fixture, 'some_project', 'SomeFile') do |content|
|
83
107
|
assert_matches /Living Jest enough for the City and SomeProject/, content
|
@@ -103,7 +127,7 @@ class GeneratorTest < Test::Unit::TestCase
|
|
103
127
|
|
104
128
|
should "notify user of all files created" do
|
105
129
|
@generator.input = 'some_project'
|
106
|
-
@string_io.expects(:puts).with('Skipped
|
130
|
+
@string_io.expects(:puts).with('Skipped directory: .')
|
107
131
|
@string_io.expects(:puts).with('Created directory: ./some_project')
|
108
132
|
@string_io.expects(:puts).with('Created file: ./some_project/SomeFile')
|
109
133
|
@string_io.expects(:puts).with('Created file: ./some_project/SomeOtherFile')
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- pre
|
10
|
-
version: 1.1.
|
10
|
+
version: 1.1.4.pre
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luke Bayes
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-31 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -302,6 +302,7 @@ files:
|
|
302
302
|
- test/fixtures/executable/echochamber_gem/echo_chamber.rb
|
303
303
|
- test/fixtures/executable/fdb.rb
|
304
304
|
- test/fixtures/executable/flex3sdk_gem/fdb
|
305
|
+
- test/fixtures/executable/flex3sdk_gem/fdb.bat
|
305
306
|
- test/fixtures/executable/flex3sdk_gem/flex3sdk.rb
|
306
307
|
- test/fixtures/executable/flex3sdk_gem/mxmlc
|
307
308
|
- test/fixtures/executable/flex3sdk_gem/mxmlc.bat
|