do_riak 0.10.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Gemfile +9 -0
- data/LICENSE +20 -0
- data/README.textile +23 -0
- data/TODO.txt +4 -0
- data/deps.rip +8 -0
- data/do_riak.gemspec +40 -0
- data/do_riak.pre.gemspec +8 -0
- data/gems/cache/bacon-1.1.0.gem +0 -0
- data/gems/cache/code-cleaner-0.8.1.gem +0 -0
- data/gems/cache/nake-0.0.8.gem +0 -0
- data/gems/cache/term-ansicolor-1.0.4.gem +0 -0
- data/gems/environment.rb +107 -0
- data/gems/gems/bacon-1.1.0/COPYING +18 -0
- data/gems/gems/bacon-1.1.0/ChangeLog +220 -0
- data/gems/gems/bacon-1.1.0/RDOX +69 -0
- data/gems/gems/bacon-1.1.0/README +290 -0
- data/gems/gems/bacon-1.1.0/Rakefile +138 -0
- data/gems/gems/bacon-1.1.0/bin/bacon +117 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/bacon.rb +36 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/bacon_rspec.rb +2 -0
- data/gems/gems/bacon-1.1.0/lib/autotest/discover.rb +9 -0
- data/gems/gems/bacon-1.1.0/lib/bacon.rb +354 -0
- data/gems/gems/bacon-1.1.0/test/spec_bacon.rb +374 -0
- data/gems/gems/bacon-1.1.0/test/spec_should.rb +32 -0
- data/gems/gems/code-cleaner-0.8.1/LICENSE +20 -0
- data/gems/gems/code-cleaner-0.8.1/README.textile +87 -0
- data/gems/gems/code-cleaner-0.8.1/TODO.txt +1 -0
- data/gems/gems/code-cleaner-0.8.1/bin/code-cleaner +143 -0
- data/gems/gems/code-cleaner-0.8.1/code-cleaner-0.8.gem +0 -0
- data/gems/gems/code-cleaner-0.8.1/code-cleaner.gemspec +25 -0
- data/gems/gems/code-cleaner-0.8.1/support/pre-commit.erb +70 -0
- data/gems/gems/code-cleaner-0.8.1/tasks.rb +13 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.nake +49 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.rake +22 -0
- data/gems/gems/code-cleaner-0.8.1/tasks/code-cleaner.thor +35 -0
- data/gems/gems/nake-0.0.8/CHANGELOG +48 -0
- data/gems/gems/nake-0.0.8/LICENSE +20 -0
- data/gems/gems/nake-0.0.8/README.textile +39 -0
- data/gems/gems/nake-0.0.8/TODO.txt +23 -0
- data/gems/gems/nake-0.0.8/bin/nake +66 -0
- data/gems/gems/nake-0.0.8/bin/nrake +4 -0
- data/gems/gems/nake-0.0.8/bin/rake2nake +1 -0
- data/gems/gems/nake-0.0.8/bin/snake +41 -0
- data/gems/gems/nake-0.0.8/bm/Rakefile +28 -0
- data/gems/gems/nake-0.0.8/bm/bms.rb +56 -0
- data/gems/gems/nake-0.0.8/bm/output.txt +5 -0
- data/gems/gems/nake-0.0.8/bm/tasks.rb +21 -0
- data/gems/gems/nake-0.0.8/bm/tmp/test.c +6 -0
- data/gems/gems/nake-0.0.8/bm/tmp/www/index.html +1 -0
- data/gems/gems/nake-0.0.8/deps.rb +5 -0
- data/gems/gems/nake-0.0.8/deps.rip +5 -0
- data/gems/gems/nake-0.0.8/examples/arguments.rb +38 -0
- data/gems/gems/nake-0.0.8/examples/basic.rb +5 -0
- data/gems/gems/nake-0.0.8/examples/boot.rb +18 -0
- data/gems/gems/nake-0.0.8/examples/complex.rb +9 -0
- data/gems/gems/nake-0.0.8/examples/configuration.rb +15 -0
- data/gems/gems/nake-0.0.8/examples/default.rb +10 -0
- data/gems/gems/nake-0.0.8/examples/default_proc.rb +11 -0
- data/gems/gems/nake-0.0.8/examples/dependencies.rb +10 -0
- data/gems/gems/nake-0.0.8/examples/description.rb +33 -0
- data/gems/gems/nake-0.0.8/examples/file.rb +22 -0
- data/gems/gems/nake-0.0.8/examples/helpers.rb +3 -0
- data/gems/gems/nake-0.0.8/examples/invoking.rb +14 -0
- data/gems/gems/nake-0.0.8/examples/rules.rb +0 -0
- data/gems/gems/nake-0.0.8/examples/script.rb +20 -0
- data/gems/gems/nake-0.0.8/examples/task_arguments.rb +27 -0
- data/gems/gems/nake-0.0.8/features/arguments.feature +22 -0
- data/gems/gems/nake-0.0.8/features/basic.feature +6 -0
- data/gems/gems/nake-0.0.8/features/boot.feature +5 -0
- data/gems/gems/nake-0.0.8/features/builtin_arguments.feature +14 -0
- data/gems/gems/nake-0.0.8/features/complex.feature +6 -0
- data/gems/gems/nake-0.0.8/features/configuration.feature +10 -0
- data/gems/gems/nake-0.0.8/features/default.feature +10 -0
- data/gems/gems/nake-0.0.8/features/default_proc.feature +6 -0
- data/gems/gems/nake-0.0.8/features/dependencies.feature +16 -0
- data/gems/gems/nake-0.0.8/features/description.feature +0 -0
- data/gems/gems/nake-0.0.8/features/env.rb +11 -0
- data/gems/gems/nake-0.0.8/features/executable.feature +29 -0
- data/gems/gems/nake-0.0.8/features/file.feature +23 -0
- data/gems/gems/nake-0.0.8/features/helpers.feature +6 -0
- data/gems/gems/nake-0.0.8/features/invoking.feature +14 -0
- data/gems/gems/nake-0.0.8/features/rules.feature +0 -0
- data/gems/gems/nake-0.0.8/features/script.feature +10 -0
- data/gems/gems/nake-0.0.8/features/steps.rb +39 -0
- data/gems/gems/nake-0.0.8/features/task_arguments.feature +10 -0
- data/gems/gems/nake-0.0.8/lib/nake.rb +103 -0
- data/gems/gems/nake-0.0.8/lib/nake/abstract_task.rb +175 -0
- data/gems/gems/nake-0.0.8/lib/nake/args.rb +65 -0
- data/gems/gems/nake-0.0.8/lib/nake/argv.rb +47 -0
- data/gems/gems/nake-0.0.8/lib/nake/colors.rb +22 -0
- data/gems/gems/nake-0.0.8/lib/nake/dsl.rb +70 -0
- data/gems/gems/nake-0.0.8/lib/nake/file_task.rb +62 -0
- data/gems/gems/nake-0.0.8/lib/nake/helpers.rb +65 -0
- data/gems/gems/nake-0.0.8/lib/nake/rake.rb +38 -0
- data/gems/gems/nake-0.0.8/lib/nake/rule.rb +35 -0
- data/gems/gems/nake-0.0.8/lib/nake/struct_hash.rb +22 -0
- data/gems/gems/nake-0.0.8/lib/nake/task.rb +6 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/bundle.rb +30 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/clean.rb +12 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/gem.rb +29 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/release.rb +43 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/rip.rb +33 -0
- data/gems/gems/nake-0.0.8/lib/nake/tasks/spec.rb +20 -0
- data/gems/gems/nake-0.0.8/lib/nake/template.rb +51 -0
- data/gems/gems/nake-0.0.8/nake-0.0.8.pre.gem +0 -0
- data/gems/gems/nake-0.0.8/nake.gemspec +42 -0
- data/gems/gems/nake-0.0.8/nake.pre.gemspec +8 -0
- data/gems/gems/nake-0.0.8/spec/nake/abstract_task_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/args_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/argv_spec.rb +51 -0
- data/gems/gems/nake-0.0.8/spec/nake/colors_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/dsl_spec.rb +35 -0
- data/gems/gems/nake-0.0.8/spec/nake/file_task_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/helpers_spec.rb +14 -0
- data/gems/gems/nake-0.0.8/spec/nake/rake_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/rule_spec.rb +72 -0
- data/gems/gems/nake-0.0.8/spec/nake/struct_hash_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/task_spec.rb +72 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/bundle_spec.rb +28 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/clean_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/gem_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/release_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/rip_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks/spec_spec.rb +0 -0
- data/gems/gems/nake-0.0.8/spec/nake/tasks_spec.rb +48 -0
- data/gems/gems/nake-0.0.8/spec/nake/template_spec.rb +84 -0
- data/gems/gems/nake-0.0.8/spec/nake_spec.rb +9 -0
- data/gems/gems/nake-0.0.8/spec/spec.opts +5 -0
- data/gems/gems/nake-0.0.8/spec/spec_helper.rb +29 -0
- data/gems/gems/nake-0.0.8/spec/stubs/database.yml.erb +9 -0
- data/gems/gems/nake-0.0.8/spec/stubs/database.yml.tt +9 -0
- data/gems/gems/nake-0.0.8/tasks.rb +42 -0
- data/gems/gems/term-ansicolor-1.0.4/CHANGES +22 -0
- data/gems/gems/term-ansicolor-1.0.4/COPYING +340 -0
- data/gems/gems/term-ansicolor-1.0.4/README +31 -0
- data/gems/gems/term-ansicolor-1.0.4/Rakefile +86 -0
- data/gems/gems/term-ansicolor-1.0.4/VERSION +1 -0
- data/gems/gems/term-ansicolor-1.0.4/doc-main.txt +119 -0
- data/gems/gems/term-ansicolor-1.0.4/examples/cdiff.rb +19 -0
- data/gems/gems/term-ansicolor-1.0.4/examples/example.rb +89 -0
- data/gems/gems/term-ansicolor-1.0.4/install.rb +15 -0
- data/gems/gems/term-ansicolor-1.0.4/lib/term/ansicolor.rb +102 -0
- data/gems/gems/term-ansicolor-1.0.4/lib/term/ansicolor/version.rb +10 -0
- data/gems/gems/term-ansicolor-1.0.4/term-ansicolor.gemspec +20 -0
- data/gems/specifications/bacon-1.1.0.gemspec +30 -0
- data/gems/specifications/code-cleaner-0.8.1.gemspec +31 -0
- data/gems/specifications/nake-0.0.8.gemspec +35 -0
- data/gems/specifications/term-ansicolor-1.0.4.gemspec +30 -0
- data/lib/do_riak.rb +10 -0
- data/lib/do_riak/errors.rb +11 -0
- data/lib/do_riak/transaction.rb +24 -0
- data/lib/do_riak/version.rb +7 -0
- data/script/bacon +3 -0
- data/script/code-cleaner +3 -0
- data/script/nake +3 -0
- data/spec/command_spec.rb +8 -0
- data/spec/connection_spec.rb +17 -0
- data/spec/reader_spec.rb +8 -0
- data/spec/result_spec.rb +12 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/typecast/array_spec.rb +8 -0
- data/spec/typecast/bigdecimal_spec.rb +8 -0
- data/spec/typecast/boolean_spec.rb +8 -0
- data/spec/typecast/byte_array_spec.rb +8 -0
- data/spec/typecast/class_spec.rb +8 -0
- data/spec/typecast/date_spec.rb +8 -0
- data/spec/typecast/datetime_spec.rb +8 -0
- data/spec/typecast/float_spec.rb +12 -0
- data/spec/typecast/integer_spec.rb +8 -0
- data/spec/typecast/nil_spec.rb +16 -0
- data/spec/typecast/other_spec.rb +8 -0
- data/spec/typecast/range_spec.rb +8 -0
- data/spec/typecast/string_spec.rb +8 -0
- data/spec/typecast/time_spec.rb +8 -0
- data/tasks.rb +37 -0
- metadata +238 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "nake/colors"
|
4
|
+
require "nake/argv"
|
5
|
+
|
6
|
+
module Nake
|
7
|
+
TaskNotFound ||= Class.new(StandardError)
|
8
|
+
ConfigurationError ||= Class.new(StandardError)
|
9
|
+
|
10
|
+
class AbstractTask
|
11
|
+
def self.[](name)
|
12
|
+
self.tasks[name.to_s]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.[]=(name, task)
|
16
|
+
self.tasks[name.to_s] = task
|
17
|
+
end
|
18
|
+
|
19
|
+
# @protected use Task[name] resp. Task[name] = task
|
20
|
+
def self.tasks
|
21
|
+
@@tasks ||= Hash.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.boot
|
25
|
+
self.tasks.each do |name, task|
|
26
|
+
task.boot!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# return existing task if task with given name already exist
|
31
|
+
def self.new(name, *dependencies, &block)
|
32
|
+
task = self[name]
|
33
|
+
task && task.setup(*dependencies, &block) || super(name, *dependencies, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_accessor :name, :dependencies, :hidden, :original_args
|
37
|
+
attr_reader :blocks
|
38
|
+
def initialize(name, *dependencies, &block)
|
39
|
+
@hidden = false
|
40
|
+
@name, @blocks = name.to_sym, Array.new
|
41
|
+
@dependencies = Array.new
|
42
|
+
self.register
|
43
|
+
self.setup(*dependencies, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_writer :description
|
47
|
+
def description
|
48
|
+
if @description.respond_to?(:call)
|
49
|
+
# task.description = lambda { "Edit #{self.config[:task_file]}" }
|
50
|
+
@description.call
|
51
|
+
elsif @description
|
52
|
+
# task.description = "Edit %{task_file}"
|
53
|
+
@description % self.config
|
54
|
+
else
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
attr_writer :config # don't use this if you don't have to!
|
60
|
+
def config
|
61
|
+
@config ||= begin
|
62
|
+
Hash.new do |hash, key|
|
63
|
+
raise ConfigurationError, "Configuration key #{key} in task #{name} doesn't exist"
|
64
|
+
end.tap do |hash|
|
65
|
+
hash.define_singleton_method(:declare) do |*keys|
|
66
|
+
keys.each { |key| self[key] = nil unless self.has_key?(key) }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def setup(*dependencies, &block)
|
73
|
+
self.dependencies.push(*dependencies)
|
74
|
+
self.instance_exec(self, &block) if block
|
75
|
+
return self
|
76
|
+
end
|
77
|
+
|
78
|
+
def define(&block)
|
79
|
+
@blocks.push(block)
|
80
|
+
end
|
81
|
+
|
82
|
+
def hidden?
|
83
|
+
@hidden
|
84
|
+
end
|
85
|
+
|
86
|
+
def run(args)
|
87
|
+
self.original_args = args
|
88
|
+
options = ArgvParser.extract!(args)
|
89
|
+
self.call(args, options)
|
90
|
+
end
|
91
|
+
|
92
|
+
# NOTE: the reason why we don't have splat for args is that when we have Task["-T"]
|
93
|
+
# which doesn't have any args and options, we wall just call it without any arguments,
|
94
|
+
# but when we use splat, then we will have to call it at least with Hash.new for options
|
95
|
+
def call(args = Array.new, options = Hash.new)
|
96
|
+
unless self.dependencies.empty?
|
97
|
+
info "Invoking task #{name}"
|
98
|
+
self.invoke_dependencies(*args, options)
|
99
|
+
end
|
100
|
+
unless self.blocks.empty?
|
101
|
+
note "Executing task #{name} with arguments #{args.inspect} and options #{options.inspect}"
|
102
|
+
debug "Config #{self.config.inspect}"
|
103
|
+
self.blocks.each do |block|
|
104
|
+
block.call(*args, options)
|
105
|
+
end
|
106
|
+
## we can't use arity, because it returns 0 for lambda { |options = Hash.new| }.arity
|
107
|
+
## if we define method with one optional argument, it will returns -1
|
108
|
+
#
|
109
|
+
## better argv parsing maybe, task(:spec) do |*paths, options| is fine, but task(:spec) do |path, options| will fail if no path specified ... but actually task(:spec) do |path = "spec", options| might be fine, try it ... BTW task(["-i", "--interactive"]) do |task, *args, options| doesn't work ... putting options as a first argument should solve everything, but it's not very intuitive :/
|
110
|
+
#if RUBY_VERSION >= "1.9.2"
|
111
|
+
# raise ArgumentError, "Task can't take block arguments" if args.length + 1 > block.parameters.select { |type, name| type.eql?(:req) || type.eql?(:opt) }.length
|
112
|
+
# raise ArgumentError, "Task can't take block arguments" if block.parameters.any? { |type, name| type.eql?(:block) }
|
113
|
+
#end
|
114
|
+
#
|
115
|
+
#if RUBY_VERSION >= "1.9.2" && block.parameters.empty?
|
116
|
+
# block.call
|
117
|
+
#else
|
118
|
+
# block.call(*args, options)
|
119
|
+
#end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def bootloaders
|
124
|
+
@bootloaders ||= Array.new
|
125
|
+
end
|
126
|
+
|
127
|
+
def boot_dependencies
|
128
|
+
@boot_dependencies ||= Array.new
|
129
|
+
end
|
130
|
+
|
131
|
+
def boot(*dependencies, &block)
|
132
|
+
self.boot_dependencies.push(*dependencies)
|
133
|
+
self.bootloaders.push(block)
|
134
|
+
end
|
135
|
+
|
136
|
+
def boot!
|
137
|
+
unless self.boot_dependencies.empty? && self.bootloaders.empty?
|
138
|
+
note "Booting #{self.name}"
|
139
|
+
end
|
140
|
+
while dependency = self.boot_dependencies.shift
|
141
|
+
self.class[dependency].tap do |task|
|
142
|
+
if task.nil?
|
143
|
+
raise TaskNotFound, "Task #{dependency} doesn't exist!"
|
144
|
+
end
|
145
|
+
task.boot!
|
146
|
+
end
|
147
|
+
end
|
148
|
+
while block = self.bootloaders.shift
|
149
|
+
block.call
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def booted?
|
154
|
+
self.bootloaders.empty? && self.boot_dependencies.empty?
|
155
|
+
end
|
156
|
+
|
157
|
+
def reset!
|
158
|
+
self.dependencies.clear
|
159
|
+
self.blocks.clear
|
160
|
+
end
|
161
|
+
|
162
|
+
protected
|
163
|
+
def invoke_dependencies(*args, options)
|
164
|
+
self.dependencies.each do |name|
|
165
|
+
task = self.class[name]
|
166
|
+
raise TaskNotFound, "Task with name #{name} doesn't exist" if task.nil?
|
167
|
+
task.call(*args, options) # TODO: what about arguments?
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def register
|
172
|
+
self.class[self.name] = self
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "nake/dsl"
|
4
|
+
|
5
|
+
argument("-H", "--help") do |task_name = nil|
|
6
|
+
if task_name
|
7
|
+
task = Task[task_name]
|
8
|
+
if task
|
9
|
+
p task # TODO
|
10
|
+
else
|
11
|
+
abort "Task #{task_name} doesn't exist"
|
12
|
+
end
|
13
|
+
else
|
14
|
+
Kernel.abort "Use #{$0} -T for list of all available tasks or -i for interactive session"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
argument("-T", "--tasks") do |pattern = nil|
|
19
|
+
Task.boot
|
20
|
+
|
21
|
+
tasks, options = Task.tasks.select { |name, task| not task.hidden? }.sort.partition { |key, value| not key.match(/^-/) }
|
22
|
+
arguments = Nake.args.sort
|
23
|
+
|
24
|
+
puts "\n#{"===".yellow} #{"Available tasks".magenta} #{"===".yellow}"
|
25
|
+
if tasks.empty?
|
26
|
+
puts "No tasks defined"
|
27
|
+
else
|
28
|
+
tasks.each do |name, task|
|
29
|
+
puts "#{name.green} #{task.dependencies.join(", ")} # #{task.description || "no description yet"}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
puts "\n#{"===".yellow} #{"Available arguments".magenta} #{"===".yellow}"
|
34
|
+
if arguments.empty?
|
35
|
+
puts "No arguments defined"
|
36
|
+
else
|
37
|
+
arguments.each do |names, proc|
|
38
|
+
puts "#{names.join(" or ").green}" # TODO: description
|
39
|
+
end
|
40
|
+
end
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
|
44
|
+
argument("-i", "--interactive") do |task = nil|
|
45
|
+
Task.boot
|
46
|
+
ARGV.clear # otherwise IRB will parse it
|
47
|
+
|
48
|
+
require "irb"
|
49
|
+
begin
|
50
|
+
require "irb/readline"
|
51
|
+
rescue LoadError
|
52
|
+
warn "Code completion via readline isn't available"
|
53
|
+
end
|
54
|
+
|
55
|
+
if task
|
56
|
+
Task[task].tap { |task| task.call(*args, options) }
|
57
|
+
end
|
58
|
+
|
59
|
+
IRB.start
|
60
|
+
exit! # TODO: can we do it without exit? The usecase is ./tasks.rb -i mytask, so we can set env and then run the task
|
61
|
+
end
|
62
|
+
|
63
|
+
Nake.args["--verbose", "--no-verbose"] = lambda { |key, value| Nake.verbose = value }
|
64
|
+
Nake.args["--debug", "--no-debug"] = lambda { |key, value| Nake.debug = value }
|
65
|
+
Nake.args["--coloring", "--no-coloring"] = lambda { |key, value| Nake.coloring = value }
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Nake
|
4
|
+
module ArgvParser
|
5
|
+
def self.extract!(args)
|
6
|
+
args.dup.inject(Hash.new) do |options, argument|
|
7
|
+
key, value = self.parse(argument)
|
8
|
+
if key
|
9
|
+
options[key] = value
|
10
|
+
args.delete(argument)
|
11
|
+
end
|
12
|
+
options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.extract(args)
|
17
|
+
args.inject(Hash.new) do |options, argument|
|
18
|
+
key, value = self.parse(argument)
|
19
|
+
if key
|
20
|
+
options[key] = value
|
21
|
+
end
|
22
|
+
options
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse!(argument)
|
27
|
+
self.parse(argument) || raise("Argument #{argument} can't be parsed!")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.parse(argument)
|
31
|
+
case argument
|
32
|
+
when /^--no-([^=]+)$/ # --no-git-repository
|
33
|
+
return [$1.gsub("-", "_").to_sym, false]
|
34
|
+
when /^--([^=]+)$/ # --git-repository
|
35
|
+
return [$1.gsub("-", "_").to_sym, true]
|
36
|
+
when /^--([^=]+)=([^,]+)$/ # --controller=post
|
37
|
+
key, value = $1, $2
|
38
|
+
return [key.gsub("-", "_").to_sym, value.dup]
|
39
|
+
when /^--([^=]+)=(.+)$/ # --controllers=posts,comments
|
40
|
+
key, value = $1, $2
|
41
|
+
return [key.gsub("-", "_").to_sym, value.split(",")]
|
42
|
+
else
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "term/ansicolor"
|
5
|
+
rescue LoadError
|
6
|
+
raise LoadError, "You have to install term-ansicolor gem!"
|
7
|
+
end
|
8
|
+
|
9
|
+
String.send(:include, Term::ANSIColor) # just for now, I know it's a mess
|
10
|
+
|
11
|
+
module Term::ANSIColor
|
12
|
+
def self.coloring?
|
13
|
+
if @coloring.respond_to?(:call)
|
14
|
+
@coloring.call
|
15
|
+
else
|
16
|
+
@coloring
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
Term::ANSIColor.coloring = lambda { Nake.coloring }
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "nake"
|
4
|
+
require "nake/task"
|
5
|
+
require "nake/file_task"
|
6
|
+
|
7
|
+
module Nake
|
8
|
+
module DSL
|
9
|
+
include Nake
|
10
|
+
def argument(*names, &block)
|
11
|
+
Nake.args[*names] = block
|
12
|
+
end
|
13
|
+
|
14
|
+
# desc :release, "Create a new release"
|
15
|
+
# task(:release) do
|
16
|
+
# # ...
|
17
|
+
# end
|
18
|
+
def desc(task, description)
|
19
|
+
Task.new(task).description = description
|
20
|
+
end
|
21
|
+
|
22
|
+
# Rake-style task definition
|
23
|
+
# task(:release, :build) do |task|
|
24
|
+
# # task definition
|
25
|
+
# end
|
26
|
+
def task(name, *dependencies, &block)
|
27
|
+
if block.nil?
|
28
|
+
Task.new(name, *dependencies)
|
29
|
+
else
|
30
|
+
Task.new(name, *dependencies) do |task|
|
31
|
+
task.define(&block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def file(path, *dependencies, &block)
|
37
|
+
if block.nil?
|
38
|
+
FileTask.new(path, *dependencies)
|
39
|
+
else
|
40
|
+
FileTask.new(path, *dependencies) do |task|
|
41
|
+
task.define(&block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# rule "*.o", "*.c"
|
47
|
+
# rule "**/*.o", "**/.c"
|
48
|
+
def rule(pattern, *dependencies, &block)
|
49
|
+
if block.nil?
|
50
|
+
Rule.new(pattern, *dependencies)
|
51
|
+
else
|
52
|
+
Rule.new(pattern, *dependencies) do |rule|
|
53
|
+
rule.define(&block)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def directory(path)
|
59
|
+
FileTask.new(path) do |task|
|
60
|
+
task.hidden = true # do not show in list
|
61
|
+
task.description = "Create directory #{path}"
|
62
|
+
task.define { mkdir_p path }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Object
|
69
|
+
include Nake::DSL
|
70
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "nake/abstract_task"
|
4
|
+
|
5
|
+
module Nake
|
6
|
+
class FileTask < AbstractTask
|
7
|
+
# TODO: default description na Generate #name
|
8
|
+
alias_method :path, :name
|
9
|
+
|
10
|
+
# FileTask can depend on tasks, other file tasks or just files.
|
11
|
+
# If a file task depends on a task, this task isn't supposed to change anything what ...
|
12
|
+
# ... if it's changing something, make sure the changing task is actually called before the file tasks are executed
|
13
|
+
# If the task is changing something so the file will be generated in all cases, you should rather to use normal task
|
14
|
+
# If there are some dependencies on files
|
15
|
+
# FileTask.new("www/index.html") do |task|
|
16
|
+
# task.file_dependencies.push(*FileList["images/**/*"])
|
17
|
+
# task.dependencies.push("www") # www task exist
|
18
|
+
# end
|
19
|
+
def call(args = Array.new, options = Hash.new)
|
20
|
+
will_run = true
|
21
|
+
unless self.dependencies.empty?
|
22
|
+
info "Invoking file task #{name}"
|
23
|
+
will_run = self.invoke_dependencies(*args, options)
|
24
|
+
end
|
25
|
+
if will_run && ! self.blocks.empty?
|
26
|
+
note "Executing file task #{name} with arguments #{args.inspect} and options #{options.inspect}"
|
27
|
+
debug "Config #{self.config.inspect}"
|
28
|
+
self.blocks.each do |block|
|
29
|
+
block.call(self.path, *args, options)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
warn "File task #{name} won't be executed"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
# task will be executed just if
|
38
|
+
def will_run?
|
39
|
+
file_tasks = self.dependencies.select { |name| self.class[name] }
|
40
|
+
file_tasks.any? do |path|
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def task_will_run?(path)
|
46
|
+
File.exist?(path) || File.mtime(path) < File.mtime(self.name)
|
47
|
+
end
|
48
|
+
|
49
|
+
# return true if the task need to be executed, false otherwise
|
50
|
+
def invoke_dependencies(*args, options)
|
51
|
+
self.dependencies.each do |name|
|
52
|
+
if task = self.class[name] # first try if there is a task with given name
|
53
|
+
task.call(*args, options) # TODO: what about arguments?
|
54
|
+
elsif File.exist?(name) # if not, then fallback to file
|
55
|
+
task_will_run?(name)
|
56
|
+
else
|
57
|
+
raise TaskNotFound, "Task with name #{name} doesn't exist"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|