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 @@
|
|
1
|
+
- the problem definitelly can't be solved with sleep, I was trying and it just doesn't work
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby -i
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# This is black magic!
|
5
|
+
# If you like Perl, you will probably enjoy it
|
6
|
+
# However it's easy to write and it works, so why not.
|
7
|
+
|
8
|
+
# Also be warned this script is evil – it might eat your
|
9
|
+
# cat or burn you house and I'm not responsible for it.
|
10
|
+
|
11
|
+
# == Normalize your source code == #
|
12
|
+
# 1) replace tabs by two space
|
13
|
+
# 2) remove trailing whitespace
|
14
|
+
# 3) add \n at the end of file unless it's already there
|
15
|
+
|
16
|
+
# == Usage == #
|
17
|
+
# code-cleaner app/controller/application_controller.rb
|
18
|
+
# cat app/controller/application_controller.rb | code-cleaner
|
19
|
+
#
|
20
|
+
# == Implementation == #
|
21
|
+
# The point is that ruby with -i will edit files
|
22
|
+
|
23
|
+
require "find"
|
24
|
+
|
25
|
+
$-i = "" # Windows compatibility
|
26
|
+
|
27
|
+
WHITELIST = Regexp.new(ENV["WHITELIST"] || '^(Rakefile|Thorfile|Gemfile|.+\.(rb|rake|nake|thor|task|gemspec))$')
|
28
|
+
BLACKLIST = Regexp.new(ENV["BLACKLIST"] || '/(vendor|gems)/')
|
29
|
+
|
30
|
+
def permitted?(file)
|
31
|
+
WHITELIST.match(file) && ! BLACKLIST.match(file)
|
32
|
+
end
|
33
|
+
|
34
|
+
if ARGF.nil?
|
35
|
+
abort "Hey mate, what about some arguments or piped data? How the fuck you think I work?!"
|
36
|
+
end
|
37
|
+
|
38
|
+
# help
|
39
|
+
if ARGV.include?("-h") or ARGV.include?("--help")
|
40
|
+
abort "[\e[32mUsage\e[0m]\n"\
|
41
|
+
"code-cleaner script.rb # normalize script.rb\n"\
|
42
|
+
"cat script.rb | code-cleaner # normalize standard input and print output to standard output\n"\
|
43
|
+
"\n"\
|
44
|
+
"[\e[32mOptions\e[0m]\n"\
|
45
|
+
"--encoding=utf-8 # add encoding declaration if missing\n"\
|
46
|
+
"--apply-rules # apply blacklisting and whitelisting even on explicitly specified files\n"\
|
47
|
+
"--try-apply-rules # apply rules and exit successfuly if some files left in ARGV, fail otherwise\n"\
|
48
|
+
"\n"\
|
49
|
+
"[\e[32mEnvironment Variables\e[0m]\n"\
|
50
|
+
"BLACKLIST # patterns which will be ignored, defaults to /(vendor|gems)/\n"\
|
51
|
+
"WHITELIST # patterns which won't be ignored, defaults to \.(rb|rake|nake|thor|task)$\n"\
|
52
|
+
"\n"\
|
53
|
+
"[\e[32mTricks\e[0m]\n"\
|
54
|
+
"If you want to add files from your bin or script directory into \n"\
|
55
|
+
"whitelist, use WHITELIST='(^bin/[^/]+|Rakefile|Thorfile|Gemfile$)|(^.+\.(rb|rake|nake|thor|task|gemspec)$)'"
|
56
|
+
"\n"\
|
57
|
+
"[\e[32mExamples\e[0m]\n"\
|
58
|
+
"WHITELIST='(^bin/[^/]+|Rakefile|Thorfile|Gemfile$)|(^.+\.(rb|rake|nake|thor|task|gemspec)$)'"
|
59
|
+
end
|
60
|
+
|
61
|
+
def apply_rules
|
62
|
+
original = ARGV.dup
|
63
|
+
ARGV.delete_if { |file| File.file?(file) && ! permitted?(file) }
|
64
|
+
puts "~ Skipping #{original - ARGV}" unless ARGV == original
|
65
|
+
end
|
66
|
+
|
67
|
+
if ARGV.delete("--try-apply-rules")
|
68
|
+
apply_rules
|
69
|
+
ARGV.empty? ? exit(1) : exit
|
70
|
+
end
|
71
|
+
|
72
|
+
if ARGV.delete("--apply-rules")
|
73
|
+
apply_rules
|
74
|
+
end
|
75
|
+
|
76
|
+
unless ARGV.grep(/^--encoding=(.+)$/).empty?
|
77
|
+
argument = ARGV.grep(/^--encoding=(.+)$/).first
|
78
|
+
ARGV.delete(argument)
|
79
|
+
argument.match(/^--encoding=(.+)$/)
|
80
|
+
encoding = $1.dup
|
81
|
+
else
|
82
|
+
encoding = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
# expand all directories to list of files
|
86
|
+
if ARGV.any? { |file| File.directory?(file) }
|
87
|
+
args = Array.new
|
88
|
+
ARGV.each do |item|
|
89
|
+
if File.directory?(item)
|
90
|
+
Find.find(item) do |file|
|
91
|
+
if File.file?(file) && permitted?(file)
|
92
|
+
args.push(file)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
else
|
96
|
+
args.push(item)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
ARGV.clear.push(*args)
|
100
|
+
puts "~ Expanding args into #{ARGV.inspect}"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Ruby 1.9 will warn that you can't do in place edit for stdio,
|
104
|
+
# so we will disable in place mode. Yes, in Ruby 1.9 you can finally
|
105
|
+
# turn in place mode on or off from API in better way than just $-i = false.
|
106
|
+
if ARGF.respond_to?(:inplace_mode) && ARGV.empty?
|
107
|
+
ARGF.inplace_mode = false
|
108
|
+
end
|
109
|
+
|
110
|
+
# default exit status is 10 which signalize that we actually haven't changed anything
|
111
|
+
status = 10
|
112
|
+
|
113
|
+
# This is the only way how I was able to inspect if STDIN is empty. Magic, right?
|
114
|
+
# NOTE: if this shows as a bad idea, another way might be to put "/dev/null" resp. "NUL" on Windows to the ARGV
|
115
|
+
begin
|
116
|
+
STDIN.read_nonblock(1)
|
117
|
+
rescue Errno::EAGAIN, EOFError
|
118
|
+
# The point of inspecting if STDIN and ARGV are empty is that we might
|
119
|
+
# have an empty ARGF if anything passed and if so, it will wait for an interactive input which we don't want
|
120
|
+
unless ARGV.empty?
|
121
|
+
while line = ARGF.gets
|
122
|
+
# I was trying to use ARGF.lineno.eql?(1), but it doesn't work. First problem
|
123
|
+
# was it didn't work with ARGF#each_line because IO#lineno count how many times
|
124
|
+
# IO#gets was called rather than how many \n the stream have. It isn't any
|
125
|
+
# serious problem, however when we have multiple files in ARGV, then the
|
126
|
+
# lineno isn't cleaned after the file in ARGF is switched.
|
127
|
+
# The trick with line.length == ARGF.pos is simple, IO#pos returns position
|
128
|
+
# of last character which was readed by gets or similar method, so if
|
129
|
+
# the position is same as is the line, then it has to be the first line.
|
130
|
+
if line.length == ARGF.pos && encoding && ! line.match(/^#(.*coding|\!)/) # the \! should means shebang. TODO: if there is a shebang on the first line, check if encoding declaration is on the second line
|
131
|
+
puts "# encoding: #{encoding}"
|
132
|
+
puts
|
133
|
+
end
|
134
|
+
# You might be wondering WTF is going on, I'm editing files, so I have to use File.open, do the modification on the original content and then save it. The point is we used -i switch which is good for in place editing
|
135
|
+
# flag that we actually changed the file
|
136
|
+
normalized_line = line.gsub(/\t/, " ").rstrip + "\n"
|
137
|
+
status = 0 if line != normalized_line
|
138
|
+
print normalized_line
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
exit status
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "code-cleaner"
|
6
|
+
s.version = "0.8.1"
|
7
|
+
s.authors = ["Jakub Šťastný aka Botanicus"]
|
8
|
+
s.homepage = "http://github.com/botanicus/code-cleaner"
|
9
|
+
s.summary = "Remove trailing whitespace, append missing \\n and replace tabs by two spaces"
|
10
|
+
s.description = "" # TODO: long description
|
11
|
+
s.cert_chain = nil
|
12
|
+
s.email = ["knava.bestvinensis", "gmail.com"].join("@")
|
13
|
+
s.has_rdoc = false
|
14
|
+
|
15
|
+
# so you can use load "code-cleaner.rake" in you Rakefile
|
16
|
+
s.require_paths = ["tasks"]
|
17
|
+
|
18
|
+
# files
|
19
|
+
s.files = Dir["**/*"]
|
20
|
+
s.executables = ["code-cleaner"]
|
21
|
+
s.default_executable = "code-cleaner"
|
22
|
+
|
23
|
+
# RubyForge
|
24
|
+
s.rubyforge_project = "code-cleaner"
|
25
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
echo "Entering pre-commit hook ..."
|
4
|
+
|
5
|
+
# The code-cleaner script has to be in your $PATH. Uncomment
|
6
|
+
# the following line if you have code-cleaner installed locally
|
7
|
+
<% if options[:path].nil? %>#<% end %>export PATH="<%= options[:path] || "script" %>:$PATH"
|
8
|
+
|
9
|
+
# Setup whitelisting & blacklisting
|
10
|
+
<% if options[:whitelist].nil? %>#<% end %>export WHITELIST='<%= options[:whitelist] %>'
|
11
|
+
<% if options[:blacklist].nil? %>#<% end %>export BLACKLIST='<%= options[:blacklist] %>'
|
12
|
+
|
13
|
+
# If you haven't done any commit yet,
|
14
|
+
# git diff will fail with following message:
|
15
|
+
# fatal: No HEAD commit to compare with (yet)
|
16
|
+
|
17
|
+
# TODO: how to get list of files which will be
|
18
|
+
# committed if there isn't any commit in the index yet?
|
19
|
+
# For now we just use normalize everything in current
|
20
|
+
# directory, but it isn't very good solution.
|
21
|
+
files=$(git diff --staged --name-only 2> /dev/null || echo ".")
|
22
|
+
|
23
|
+
function abort() {
|
24
|
+
printf "[\e[31mERROR\e[0m] $*\n"
|
25
|
+
exit 1
|
26
|
+
}
|
27
|
+
|
28
|
+
sleep=false
|
29
|
+
|
30
|
+
# NOTE: we are using printf rather than echo because printf should be
|
31
|
+
# more portable, each echo implementation has quite different behaviour
|
32
|
+
if which code-cleaner &> /dev/null; then
|
33
|
+
for file in $files; do
|
34
|
+
if test -f "$file" ; then # ignore files which was removed by git rm
|
35
|
+
if code-cleaner "$file" --try-apply-rules &> /dev/null ; then
|
36
|
+
printf "Normalizing \"\e[36m$file\e[0m\" "
|
37
|
+
code-cleaner "$file" --apply-rules <%= "--encoding=#{options[:encoding]} " if options[:encoding] %>&> /dev/null
|
38
|
+
exitstatus=$?
|
39
|
+
# NOTE: we have to check the exit status directly,
|
40
|
+
# so we can be sure that the command just wasn't found
|
41
|
+
if [ $exitstatus -eq 10 ]; then # code-cleaner exits with 0 if some changes were made
|
42
|
+
printf "[\e[32mCLEAN\e[0m]\n"
|
43
|
+
elif [ $exitstatus -eq 1 ]; then # something goes wrong
|
44
|
+
printf "[\e[31mERROR\e[0m]\n"
|
45
|
+
echo "code-cleaner \"$file\" --apply-rules <%= "--encoding=#{options[:encoding]} " if options[:encoding] %>"
|
46
|
+
code-cleaner "$file" --apply-rules <%= "--encoding=#{options[:encoding]} " if options[:encoding] %>
|
47
|
+
echo "Exited with status $?"
|
48
|
+
exit 1
|
49
|
+
elif [ $exitstatus -eq 0 ] ; then
|
50
|
+
printf "[\e[33mDONE\e[0m]\n"
|
51
|
+
sleep=true # otherwise it might not work
|
52
|
+
else
|
53
|
+
abort "Unexpected exit status $?"
|
54
|
+
fi
|
55
|
+
else
|
56
|
+
printf "Skipping \"\e[36m$file\e[0m\"\n"
|
57
|
+
fi
|
58
|
+
fi
|
59
|
+
done
|
60
|
+
|
61
|
+
# otherwise it doesn't work time to time
|
62
|
+
$sleep && sleep 0.8
|
63
|
+
for file in $files; do
|
64
|
+
test -f "$file" && git add "$file" # so the changes will be committed immediately
|
65
|
+
done
|
66
|
+
else
|
67
|
+
abort "You have to have code-cleaner installed and the code-cleaner script has to be in your \$PATH ($PATH)"
|
68
|
+
fi
|
69
|
+
|
70
|
+
exit 0
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env nake
|
2
|
+
|
3
|
+
begin
|
4
|
+
load "./tasks/code-cleaner.nake"
|
5
|
+
rescue LoadError
|
6
|
+
abort "If you want to contribute to code-cleaner, you have to run ./tasks.rb hooks:whitespace:install first!"
|
7
|
+
end
|
8
|
+
|
9
|
+
Nake::Task["hooks:whitespace:install"].tap do |task|
|
10
|
+
task.config[:path] = "bin"
|
11
|
+
task.config[:encoding] = "utf-8"
|
12
|
+
task.config[:whitelist] = '(bin/[^/]+|.+\.(rb|rake|nake|thor|task|gemspec))$'
|
13
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "erb"
|
4
|
+
require "fileutils"
|
5
|
+
require "nake/task"
|
6
|
+
|
7
|
+
# nake hooks:whitespace:install
|
8
|
+
# nake hooks:whitespace:install --force
|
9
|
+
# nake hooks:whitespace:install --path=script
|
10
|
+
# nake hooks:whitespace:install --encoding=utf-8
|
11
|
+
# nake hooks:whitespace:install --whitelist=pattern
|
12
|
+
# nake hooks:whitespace:install --blacklist=pattern
|
13
|
+
Nake::Task.new("hooks:whitespace:install") do |task|
|
14
|
+
task.config.declare(:path, :encoding, :whitelist, :blacklist)
|
15
|
+
task.description = "Install hook for automatically removing trailing whitespace"
|
16
|
+
task.define do |options = Hash.new|
|
17
|
+
# --force
|
18
|
+
if File.exist?(".git/hooks/pre-commit") && options[:force]
|
19
|
+
FileUtils.rm ".git/hooks/pre-commit"
|
20
|
+
end
|
21
|
+
|
22
|
+
# --path=script
|
23
|
+
options[:path] = task.config[:path] unless options[:path]
|
24
|
+
|
25
|
+
# --encoding=utf-8
|
26
|
+
options[:encoding] = task.config[:encoding] unless options[:encoding]
|
27
|
+
|
28
|
+
# --whitelist=pattern
|
29
|
+
options[:whitelist] = task.config[:whitelist] unless options[:whitelist]
|
30
|
+
|
31
|
+
# --blacklist=pattern
|
32
|
+
options[:blacklist] = task.config[:blacklist] unless options[:blacklist]
|
33
|
+
|
34
|
+
if File.exist?(".git/hooks/pre-commit")
|
35
|
+
abort "The hook .git/hooks/pre-commit already exists. Run this task with --force if you want to overwrite it."
|
36
|
+
else
|
37
|
+
begin
|
38
|
+
puts "Installing .git/hooks/pre-commit ..."
|
39
|
+
source = File.join(File.dirname(__FILE__), "..", "support", "pre-commit.erb")
|
40
|
+
File.open(".git/hooks/pre-commit", "w") do |file|
|
41
|
+
file.puts(ERB.new(File.read(source)).result(binding))
|
42
|
+
end
|
43
|
+
File.chmod(0755, ".git/hooks/pre-commit")
|
44
|
+
rescue Errno::ENOENT
|
45
|
+
abort "You have to run git init first!"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# The task for Rake doesn't support any options. Sorry, your task utility sucks, get something better.
|
4
|
+
# The reason why I can't add --path option is that Rake has very nasty bug http://gist.github.com/263325
|
5
|
+
# Yeah, I know I can use environment varibles, but why I should bother when you can just install nake which is so much better!
|
6
|
+
desc "Install hook for automatically removing trailing whitespace"
|
7
|
+
task "hooks:whitespace:install" do
|
8
|
+
if File.exist?(".git/hooks/pre-commit")
|
9
|
+
abort "You must remove .git/hooks/pre-commit first!"
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
puts "Installing .git/hooks/pre-commit ..."
|
13
|
+
source = File.join(File.dirname(__FILE__), "..", "support", "pre-commit.erb")
|
14
|
+
File.open(".git/hooks/pre-commit", "w") do |file|
|
15
|
+
file.puts(ERB.new(File.read(source)).result)
|
16
|
+
end
|
17
|
+
File.chmod(0755, ".git/hooks/pre-commit")
|
18
|
+
rescue Errno::ENOENT
|
19
|
+
abort "You have to run git init first!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
# thor hooks:whitespace:install
|
6
|
+
# thor hooks:whitespace:install --force
|
7
|
+
# thor hooks:whitespace:install --path=script
|
8
|
+
# nake hooks:whitespace:install --encoding=utf-8
|
9
|
+
# nake hooks:whitespace:install --whitelist=pattern
|
10
|
+
# nake hooks:whitespace:install --blacklist=pattern
|
11
|
+
module Hooks
|
12
|
+
class Whitespace < Thor
|
13
|
+
method_options :force => :boolean, :path => :string, :encoding => :string, :whitelist => :string, :blacklist => :string
|
14
|
+
desc "install", "Install hook for automatically removing trailing whitespace"
|
15
|
+
def install
|
16
|
+
# --force
|
17
|
+
if File.exist?(".git/hooks/pre-commit") && options[:force]
|
18
|
+
FileUtils.rm ".git/hooks/pre-commit"
|
19
|
+
end
|
20
|
+
|
21
|
+
if File.exist?(".git/hooks/pre-commit")
|
22
|
+
abort "You must remove .git/hooks/pre-commit first!"
|
23
|
+
else
|
24
|
+
puts "Installing .git/hooks/pre-commit ..."
|
25
|
+
source = File.join(File.dirname(__FILE__), "..", "support", "pre-commit.erb")
|
26
|
+
File.open(".git/hooks/pre-commit", "w") do |file|
|
27
|
+
file.puts(ERB.new(File.read(source)).result(binding))
|
28
|
+
end
|
29
|
+
File.chmod(0755, ".git/hooks/pre-commit")
|
30
|
+
end
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
abort "You have to run git init first!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
= Version 0.0.1
|
2
|
+
* bin/nake executable
|
3
|
+
* sh helper (nake/helpers)
|
4
|
+
* task helper (nake/dsl)
|
5
|
+
* Task with description, dependencies and blocks
|
6
|
+
* Hidden tasks
|
7
|
+
* Each task can has multiple aliases
|
8
|
+
* Command line arguments parsing. Arguments will be passed as an arguments for blocks of the given task and options will be extracted into a hash, parsed into Ruby data types and passed as the last argument for the blocks.
|
9
|
+
* Default tasks for help (-H, --help), list of available tasks (-T, --tasks) and interactive session (-i, --interactive)
|
10
|
+
|
11
|
+
= Version 0.0.2
|
12
|
+
* Support for configuration
|
13
|
+
* A lot of useful tasks for releasing, prereleasing, bundling, specs, clean etc.
|
14
|
+
|
15
|
+
= Version 0.0.3
|
16
|
+
* Some bug fixes and task improvements
|
17
|
+
|
18
|
+
= Version 0.0.4
|
19
|
+
* Support for arguments parsing
|
20
|
+
* FileTask & file & directory helpers
|
21
|
+
|
22
|
+
= Version 0.0.5
|
23
|
+
* Benchmarks
|
24
|
+
* Some bug fixes
|
25
|
+
|
26
|
+
= Version 0.0.6
|
27
|
+
* Cucumber features
|
28
|
+
* DSL helper rule
|
29
|
+
|
30
|
+
= Version 0.0.7
|
31
|
+
* Added Task#boot method for setting some stuff after other tasks boot
|
32
|
+
* Added DSL helper desc
|
33
|
+
* Removed task aliases
|
34
|
+
|
35
|
+
= Version 0.0.8
|
36
|
+
* Added Nake::Template & template helper
|
37
|
+
* Added Nake::ErbTemplate & erb helper
|
38
|
+
* Added bin/snake for system-wide tasks
|
39
|
+
* Added AbstractTask base class
|
40
|
+
* Exit with the status of the spec command to help CI stuff out some
|
41
|
+
* "nake --H build" can provide more informations about given task
|
42
|
+
* Task.description can use %{foo} and it will be replaced by values from its config hash
|
43
|
+
* Task.description can be a callable object
|
44
|
+
|
45
|
+
= Version 0.0.9
|
46
|
+
* Thanks to Task#config=, the configuration can be shared between multiple tasks
|
47
|
+
* Reworked rule, added Rule class
|
48
|
+
* Added --coloring & --no-coloring options
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 – 2010 Jakub Šťastný aka Botanicus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,39 @@
|
|
1
|
+
h1. About
|
2
|
+
|
3
|
+
Nake is light-weight and highly flexible Rake replacement with much better arguments parsing.
|
4
|
+
|
5
|
+
You might be wondering why to write yet another fucking task manager when we have Rake, Thor and others. Well, because all of them suck. For example Rake, anyone is actually using its CLI arguments, because it sucks so much, that everyone rather write @ENV=test VERSION=10 rake db:migrate@. It has not just shitty API for defining CLI arguments, but also it is using very weird and totally non-unix syntax like @rake db:migrate[test,10]@. This syntax isn't just non-standard, but also some shells has @[]@ as special characters, so you actually has to escape it.
|
6
|
+
|
7
|
+
Sounds terrible? Well and it's not all! Let's take a look at this "example":http://gist.github.com/263325, as you can see if you have argument path and you let it empty, than it takes environment variable @$PATH@! I contact Jim Weirich so I hope he will remove this awful bug, but hey, it's pretty bad anyway.
|
8
|
+
|
9
|
+
h1. Features
|
10
|
+
|
11
|
+
- Tasks can have a *name*, *description*, *dependencies*, and *blocks* which will be executed when the task is called. Task can be also hidden if you don't want to list it in the list of available tasks.
|
12
|
+
- You can use `nake` in *shebang*, so you can use your file with tasks as a runner.
|
13
|
+
- *Arguments parsing*, everything what start with @--@ will be passed into options hash and everything other will be treated as an arguments. Both arguments and options will be passed as a block arguments for task, so you don't have to learn any new API, just use normal Ruby expressions as you are used to. Options are parsed into Ruby data types, so if you have @--without-mysql@, you'll get @{mysql: false}@, if you have @--name=botanicus@, you'll get @{name: "botanicus"}@ etc.
|
14
|
+
- *Configuration support*, so you don't have to use bunch of constants as in Rake. Example: @Task[:clean].config[:files] = Dir.glob("*.gem")@
|
15
|
+
- *Arbitrary names of tasks* is one of the key features of Nake. This way you can *namespace* your tasks (like @nake build:prerelease@) or you can define tasks like @-T@.
|
16
|
+
- Two level of API for defining tasks. @task@ helper is useful for defining simple tasks and if you need something more complicated, you can use @Task.new@
|
17
|
+
- *Interactive session* if you run @nake -i@ or @nake -i task@ you get an interactive nake session.
|
18
|
+
|
19
|
+
h1. Installation
|
20
|
+
|
21
|
+
_Before installation, please ensure that you are running on Ruby 1.9 or higher, Ruby 1.8 isn't supported!_
|
22
|
+
|
23
|
+
* From Gemcutter: @gem install nake@
|
24
|
+
* JRuby: @jruby --1.9 -S gem install nake@
|
25
|
+
* Install edge version via "Rip":http://hellorip.com: @rip install git://github.com/botanicus/nake.git@
|
26
|
+
* Install tagged version via "Rip":http://hellorip.com: @rip install git://github.com/botanicus/nake.git 0.1@
|
27
|
+
|
28
|
+
h1. Usage
|
29
|
+
|
30
|
+
First of all there is a bunch of "examples":github.com/botanicus/nake/tree/master/examples, so you can try them. All these scripts are executable, so just run @./executable/basic.rb -T@ and that's it!
|
31
|
+
|
32
|
+
h1. Links
|
33
|
+
|
34
|
+
* "Nake Wiki":http://wiki.github.com/botanicus/nake
|
35
|
+
* "RDoc.info API Docs":http://rdoc.info/projects/botanicus/nake
|
36
|
+
* "Yardoc.org API Docs":http://yardoc.org/docs/botanicus-nake
|
37
|
+
* "Examples":http://github.com/botanicus/nake/tree/master/examples
|
38
|
+
* "Bug reporting":http://github.com/botanicus/nake/issues
|
39
|
+
* "Caliper Code Metrics":http://devver.net/caliper/project?repo=git%3A%2F%2Fgithub.com%2Fbotanicus%2Fnake.git
|