falsework 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.rdoc +6 -5
- data/Rakefile +14 -10
- data/bin/falsework +25 -25
- data/doc/NEWS.rdoc +18 -0
- data/doc/README.rdoc +6 -5
- data/doc/TODO.org +2 -1
- data/lib/falsework/cliconfig.rb +135 -0
- data/lib/falsework/cliutils.rb +112 -0
- data/lib/falsework/meta.rb +1 -1
- data/lib/falsework/mould.rb +23 -20
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/#config.yaml +0 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/.gitignore.#erb +0 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/Gemfile +1 -1
- data/lib/falsework/templates/{ruby-naive/doc → ruby-cli}/README.rdoc +1 -1
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/Rakefile +0 -0
- data/lib/falsework/templates/ruby-cli/bin/%%@project%% +26 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/doc/#doc.rdoc +1 -1
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/doc/LICENSE +0 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/doc/NEWS.rdoc +0 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli/doc}/README.rdoc +1 -1
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/etc/%%@project%%.yaml +0 -0
- data/lib/falsework/templates/ruby-cli/lib/%%@project%%/cliconfig.rb +137 -0
- data/lib/falsework/templates/ruby-cli/lib/%%@project%%/cliutils.rb +114 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/lib/%%@project%%/meta.rb +0 -0
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/test/helper.rb +1 -1
- data/lib/falsework/templates/{ruby-naive/test/helper_trestle.rb → ruby-cli/test/helper_cliutils.rb} +4 -4
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/test/rake_git.rb +2 -2
- data/lib/falsework/templates/{ruby-naive → ruby-cli}/test/test_%%@project%%.rb +0 -0
- data/test/helper.rb +1 -1
- data/test/{helper_trestle.rb → helper_cliutils.rb} +3 -3
- data/test/rake_erb_templates.rb +3 -3
- data/test/rake_git.rb +1 -1
- data/test/templates/config-02.yaml +2 -0
- data/test/test_cl.rb +9 -5
- data/test/test_exe.rb +26 -21
- metadata +31 -26
- data/lib/falsework/templates/ruby-naive/bin/%%@project%% +0 -31
- data/lib/falsework/templates/ruby-naive/lib/%%@project%%/trestle.rb +0 -230
- data/lib/falsework/trestle.rb +0 -228
data/lib/falsework/mould.rb
CHANGED
@@ -2,8 +2,9 @@ require 'git'
|
|
2
2
|
require 'erb'
|
3
3
|
require 'digest/md5'
|
4
4
|
require 'securerandom'
|
5
|
+
require 'yaml'
|
5
6
|
|
6
|
-
require_relative '
|
7
|
+
require_relative 'cliutils'
|
7
8
|
|
8
9
|
module Falsework
|
9
10
|
# The directory with template may have files beginning with # char
|
@@ -15,7 +16,7 @@ module Falsework
|
|
15
16
|
#
|
16
17
|
# %%VARIABLE%%
|
17
18
|
#
|
18
|
-
# which is equivalent of erb's: <%= VARIABLE %>. See 'ruby-
|
19
|
+
# which is equivalent of erb's: <%= VARIABLE %>. See 'ruby-cli'
|
19
20
|
# template directory for examples.
|
20
21
|
#
|
21
22
|
# In the template files you may use any Mould instance variables. The
|
@@ -37,10 +38,10 @@ module Falsework
|
|
37
38
|
# Where @user, @email & @gecos comes from.
|
38
39
|
GITCONFIG = '~/.gitconfig'
|
39
40
|
# The possible dirs for templates. The first one is system-wide.
|
40
|
-
@@template_dirs = [
|
41
|
-
|
41
|
+
@@template_dirs = [CliUtils::DIR_LIB_SRC + 'templates',
|
42
|
+
Pathname.new(Dir.home) + ".#{Meta::NAME}" + 'templates']
|
42
43
|
# The template used if user didn't select one.
|
43
|
-
TEMPLATE_DEFAULT = 'ruby-
|
44
|
+
TEMPLATE_DEFAULT = 'ruby-cli'
|
44
45
|
# A file name with configurations for the inject commands.
|
45
46
|
TEMPLATE_CONFIG = '#config.yaml'
|
46
47
|
# A list of files to ignore in any template.
|
@@ -67,7 +68,7 @@ module Falsework
|
|
67
68
|
@verbose = false
|
68
69
|
@batch = false
|
69
70
|
@template = template
|
70
|
-
@dir_t = Mould.templates[@template || TEMPLATE_DEFAULT] ||
|
71
|
+
@dir_t = Mould.templates[@template || TEMPLATE_DEFAULT] || CliUtils.errx(1, "no such template: #{template}")
|
71
72
|
|
72
73
|
# default config
|
73
74
|
@conf = {
|
@@ -97,7 +98,7 @@ module Falsework
|
|
97
98
|
[['github.user', @user],
|
98
99
|
['user.email', @email],
|
99
100
|
['user.name', @gecos]].each {|i|
|
100
|
-
|
101
|
+
CliUtils.errx(1, "missing #{i.first} in #{GITCONFIG}") if i.last.to_s == ''
|
101
102
|
}
|
102
103
|
end
|
103
104
|
|
@@ -106,8 +107,10 @@ module Falsework
|
|
106
107
|
return unless defined? dirs.each
|
107
108
|
|
108
109
|
dirs.each {|idx|
|
110
|
+
fail "#{idx} is not a Pathname" unless idx.instance_of?(Pathname)
|
111
|
+
|
109
112
|
if ! File.directory?(idx)
|
110
|
-
|
113
|
+
CliUtils.warnx "invalid additional template directory: #{idx}"
|
111
114
|
else
|
112
115
|
@@template_dirs << idx
|
113
116
|
end
|
@@ -167,7 +170,7 @@ module Falsework
|
|
167
170
|
def self.templates
|
168
171
|
r = {}
|
169
172
|
@@template_dirs.each {|i|
|
170
|
-
Dir.glob(i + '
|
173
|
+
Dir.glob(i + '*').each {|j|
|
171
174
|
r[File.basename(j)] = j if File.directory?(j)
|
172
175
|
}
|
173
176
|
}
|
@@ -181,7 +184,7 @@ module Falsework
|
|
181
184
|
uuid = Mould.uuidgen_fake # useful variable for the template
|
182
185
|
|
183
186
|
# check for existing project
|
184
|
-
|
187
|
+
CliUtils.errx(1, "directory '#{@project}' is not empty") if Dir.glob(@project + '/*').size > 0
|
185
188
|
|
186
189
|
Dir.mkdir @project unless File.directory?(@project)
|
187
190
|
puts "Project path: #{File.expand_path(@project)}" if @verbose
|
@@ -234,11 +237,11 @@ module Falsework
|
|
234
237
|
begin
|
235
238
|
myconf = YAML.load_file(file)
|
236
239
|
rescue
|
237
|
-
|
240
|
+
CliUtils.warnx "cannot parse #{file}: #{$!}"
|
238
241
|
return false
|
239
242
|
end
|
240
243
|
rvars.each { |i|
|
241
|
-
|
244
|
+
CliUtils.warnx "missing or nil '#{i}' in #{file}" if ! myconf.key?(i.to_sym) || ! myconf[i.to_sym]
|
242
245
|
r = false
|
243
246
|
}
|
244
247
|
|
@@ -282,7 +285,7 @@ module Falsework
|
|
282
285
|
Mould.extract(@dir_t + '/' + idx[:src], binding, to)
|
283
286
|
File.chmod(idx[:mode_int], to) if idx[:mode_int]
|
284
287
|
rescue
|
285
|
-
|
288
|
+
CliUtils.warnx "failed to create '#{to}' (check your #config.yaml): #{$!}"
|
286
289
|
else
|
287
290
|
created << to
|
288
291
|
end
|
@@ -320,7 +323,7 @@ module Falsework
|
|
320
323
|
output = t.result(binding)
|
321
324
|
md5_system = Digest::MD5.hexdigest(output)
|
322
325
|
rescue Exception
|
323
|
-
|
326
|
+
CliUtils.errx(1, "bogus template file '#{from}': #{$!}")
|
324
327
|
end
|
325
328
|
|
326
329
|
if ! File.exists?(to)
|
@@ -330,12 +333,12 @@ module Falsework
|
|
330
333
|
# transfer the exec bit to the generated result
|
331
334
|
File.chmod(0744, to) if File.stat(from).executable?
|
332
335
|
rescue
|
333
|
-
|
336
|
+
CliUtils.errx(1, "cannot generate: #{$!}")
|
334
337
|
end
|
335
338
|
elsif
|
336
339
|
# warn a careless user
|
337
340
|
if md5_system != Digest::MD5.file(to).hexdigest
|
338
|
-
|
341
|
+
CliUtils.errx(1, "'#{to}' already exists")
|
339
342
|
end
|
340
343
|
end
|
341
344
|
end
|
@@ -346,7 +349,7 @@ module Falsework
|
|
346
349
|
|
347
350
|
re = /%%([^%]+)%%/
|
348
351
|
t = ERB.new(t.gsub(re, '<%= \+ %>')).result(binding) if t =~ re
|
349
|
-
t.sub
|
352
|
+
t.sub(/\.#erb$/, '')
|
350
353
|
end
|
351
354
|
|
352
355
|
|
@@ -359,7 +362,7 @@ module Falsework
|
|
359
362
|
def upgradable_files()
|
360
363
|
line_max = 4
|
361
364
|
r = {}
|
362
|
-
|
365
|
+
Mould.traverse(@dir_t) {|i|
|
363
366
|
next if File.directory?(i)
|
364
367
|
next if File.symlink?(i) # hm...
|
365
368
|
|
@@ -429,7 +432,7 @@ module Falsework
|
|
429
432
|
end
|
430
433
|
end
|
431
434
|
|
432
|
-
|
435
|
+
CliUtils.warnx("#{k}: unversioned") if ! is_versioned
|
433
436
|
}
|
434
437
|
end
|
435
438
|
}
|
@@ -458,7 +461,7 @@ an '.old' extension. So? }
|
|
458
461
|
u.each {|k, v|
|
459
462
|
printf("%#{tsl}s) mv %s %s\n",
|
460
463
|
"#{count}/#{total}", k, "#{k}.old") if @verbose
|
461
|
-
File.rename(k, "#{k}.old") rescue
|
464
|
+
File.rename(k, "#{k}.old") rescue CliUtils.warnx('renaming failed')
|
462
465
|
printf("%#{tsl}s Extracting %s ...\n", "", File.basename(v)) if @verbose
|
463
466
|
FileUtils.mkdir_p(File.dirname(k))
|
464
467
|
Mould.extract(v, binding, k)
|
File without changes
|
File without changes
|
@@ -21,7 +21,7 @@ The options are as follows:
|
|
21
21
|
it contains <tt>/</tt> in it, the list from
|
22
22
|
<tt>--config-dirs</tt> is ignored.
|
23
23
|
|
24
|
-
-V::
|
24
|
+
-V, --version:: Show version and exit.
|
25
25
|
|
26
26
|
-v:: Be more verbose. You can supply it several
|
27
27
|
times, viz. <tt>-vv</tt> dumps even more
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*-ruby-*-
|
3
|
+
|
4
|
+
require_relative '../lib/<%= @project %>/cliconfig'
|
5
|
+
|
6
|
+
include <%= @camelcase %>
|
7
|
+
|
8
|
+
$conf = CliConfig.new
|
9
|
+
$conf[:banner] = "Usage: #{File.basename($0)} [options] hren'"
|
10
|
+
$conf[:foobar] = ''
|
11
|
+
|
12
|
+
### main
|
13
|
+
|
14
|
+
$conf.load(['foobar']) {|o|
|
15
|
+
o.on('--foobar STR', 'An example of the option --foobar') {|i|
|
16
|
+
$conf[:foobar] = i
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
# print our env
|
21
|
+
if $conf[:verbose] >= 2
|
22
|
+
puts "Libs dir: #{CliUtils::DIR_LIB_SRC}"
|
23
|
+
pp $conf
|
24
|
+
end
|
25
|
+
|
26
|
+
puts 'Hello, World!'
|
@@ -21,7 +21,7 @@ The options are as follows:
|
|
21
21
|
it contains <tt>/</tt> in it, the list from
|
22
22
|
<tt>--config-dirs</tt> is ignored.
|
23
23
|
|
24
|
-
-V::
|
24
|
+
-V, --version:: Show version and exit.
|
25
25
|
|
26
26
|
-v:: Be more verbose. You can supply it several
|
27
27
|
times, viz. <tt>-vv</tt> dumps even more
|
File without changes
|
File without changes
|
@@ -21,7 +21,7 @@ The options are as follows:
|
|
21
21
|
it contains <tt>/</tt> in it, the list from
|
22
22
|
<tt>--config-dirs</tt> is ignored.
|
23
23
|
|
24
|
-
-V::
|
24
|
+
-V, --version:: Show version and exit.
|
25
25
|
|
26
26
|
-v:: Be more verbose. You can supply it several
|
27
27
|
times, viz. <tt>-vv</tt> dumps even more
|
File without changes
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# :erb: ruby-cli
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
require 'optparse'
|
6
|
+
require 'shellwords'
|
7
|
+
|
8
|
+
require_relative 'cliutils'
|
9
|
+
|
10
|
+
module <%= @camelcase %>
|
11
|
+
|
12
|
+
# Load configuration from 3 places (starting from least significant):
|
13
|
+
# config file, env variable, command line.
|
14
|
+
class CliConfig
|
15
|
+
# Possible config file locations.
|
16
|
+
DIR_CONFIG = [Pathname.new(Dir.home) + ".#{Meta::NAME}",
|
17
|
+
Pathname.new('/etc'),
|
18
|
+
Pathname.new('/usr/etc'),
|
19
|
+
Pathname.new('/usr/local/etc'),
|
20
|
+
CliUtils::DIR_LIB_SRC.parent.parent + 'etc']
|
21
|
+
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# conf = CliConfig.new
|
25
|
+
# conf[:my_option] = 123
|
26
|
+
# conf.load
|
27
|
+
def initialize
|
28
|
+
@conf = Hash.new
|
29
|
+
@conf[:verbose] = 0
|
30
|
+
@conf[:banner] = "Usage: #{File.basename($0)} [options]"
|
31
|
+
@conf[:config_name] = Meta::NAME + '.yaml'
|
32
|
+
@conf[:config_env] = Meta::NAME.upcase + '_CONF'
|
33
|
+
@conf[:config_dirs] = DIR_CONFIG
|
34
|
+
end
|
35
|
+
|
36
|
+
# Setter for @conf
|
37
|
+
def []=(key, val)
|
38
|
+
CliUtils.verbose = val if key == :verbose # sync verbosity levels
|
39
|
+
@conf[key] = val
|
40
|
+
end
|
41
|
+
|
42
|
+
# Getter for @conf
|
43
|
+
def [](key)
|
44
|
+
@conf[key]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Return a full path to a config file or nil if no config file found.
|
48
|
+
def getConfigPath
|
49
|
+
if @conf[:config_name].index('/')
|
50
|
+
return @conf[:config_name] if File.file?(@conf[:config_name])
|
51
|
+
else
|
52
|
+
@conf[:config_dirs].each {|i|
|
53
|
+
r = Pathname.new(i) + @conf[:config_name]
|
54
|
+
return r if File.file?(r)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
CliUtils.warnx "no config file '#{@conf[:config_name]}' found" if @conf[:verbose] >= 2
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
|
62
|
+
# Load a config from file. Return true on success or false otherwise.
|
63
|
+
def loadFile
|
64
|
+
file = getConfigPath
|
65
|
+
return false unless file
|
66
|
+
|
67
|
+
CliUtils::veputs(2, "Loading #{File.basename(file)}... " + CliUtils::NNL_MARK)
|
68
|
+
myconf = YAML.load_file(file) rescue CliUtils.errx(1, "cannot parse config #{file}: #{$!}")
|
69
|
+
# preserve existing values
|
70
|
+
@conf.merge!(myconf) {|key, oldval, newval| oldval }
|
71
|
+
CliUtils::veputs(2, "OK")
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
# Check if options in array opts are in @conf.
|
76
|
+
def requiredOptions?(opts)
|
77
|
+
opts.each {|idx|
|
78
|
+
if !@conf.key?(idx.to_sym) || !@conf[idx.to_sym]
|
79
|
+
CliUtils.errx(1, "option #{idx} is either nil or missing")
|
80
|
+
end
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
# Parse CLO and env variable. If block is given it is passed with
|
85
|
+
# OptionParser object as a parameter.
|
86
|
+
def optParse
|
87
|
+
o = OptionParser.new do |o|
|
88
|
+
o.banner = @conf[:banner]
|
89
|
+
o.banner = @conf[:banner]
|
90
|
+
o.on('-v', 'Be more verbose.') { |i|
|
91
|
+
self[:verbose] += 1
|
92
|
+
}
|
93
|
+
o.on('-V', '--version', 'Show version & exit.') { |i|
|
94
|
+
puts Meta::VERSION
|
95
|
+
exit 0
|
96
|
+
}
|
97
|
+
o.on('--config NAME',
|
98
|
+
"Set a config name or file",
|
99
|
+
"(default is #{@conf[:config_name]}).") {|arg|
|
100
|
+
@conf[:config_name] = arg
|
101
|
+
}
|
102
|
+
o.on('--config-dirs', 'Show possible config locations.') {
|
103
|
+
mark = false
|
104
|
+
@conf[:config_dirs].each { |idx|
|
105
|
+
f = Pathname(idx) + @conf[:config_name]
|
106
|
+
if File.file?(f) && !mark
|
107
|
+
puts "* #{f}"
|
108
|
+
mark = true
|
109
|
+
else
|
110
|
+
puts " #{f}"
|
111
|
+
end
|
112
|
+
}
|
113
|
+
exit 0
|
114
|
+
}
|
115
|
+
|
116
|
+
yield o if block_given?
|
117
|
+
|
118
|
+
env = nil
|
119
|
+
env = ENV[@conf[:config_env]].shellsplit if ENV.key?(@conf[:config_env])
|
120
|
+
[env, ARGV].each { |i| o.parse!(i) if i }
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Parse CLO, env variables and load config file.
|
125
|
+
#
|
126
|
+
# [reqOpts] an array of requied options
|
127
|
+
# [&block] a optional block for OptionParser
|
128
|
+
def load(reqOpts = [], &block)
|
129
|
+
optParse &block
|
130
|
+
loadFile
|
131
|
+
requiredOptions?(reqOpts)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Don't remove this: falsework/2.0.0/ruby-cli/2012-03-05T05:04:11+02:00
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# :erb: ruby-cli
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
require 'open4'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
require_relative 'meta'
|
8
|
+
|
9
|
+
module <%= @camelcase %>
|
10
|
+
|
11
|
+
# Preferable exit codes. See sysexits(3) in FreeBSD.
|
12
|
+
EX_OK = 0
|
13
|
+
EX_USAGE = 64
|
14
|
+
EX_DATAERR = 65
|
15
|
+
EX_NOINPUT = 66
|
16
|
+
EX_NOUSER = 67
|
17
|
+
EX_NOHOST = 68
|
18
|
+
EX_UNAVAILABLE = 69
|
19
|
+
EX_SOFTWARE = 70
|
20
|
+
EX_OSERR = 71
|
21
|
+
EX_OSFILE = 72
|
22
|
+
EX_CANTCREAT = 73
|
23
|
+
EX_IOERR = 74
|
24
|
+
EX_TEMPFAIL = 75
|
25
|
+
EX_PROTOCOL = 76
|
26
|
+
EX_NOPERM = 77
|
27
|
+
EX_CONFIG = 78
|
28
|
+
|
29
|
+
# Common routines useful in any CLI program.
|
30
|
+
class CliUtils
|
31
|
+
# Physical location of program libraries.
|
32
|
+
DIR_LIB_SRC = Pathname.new File.dirname(__FILE__)
|
33
|
+
# veputs uses this to decide to put a newline or not to put.
|
34
|
+
NNL_MARK = '__NNL__'
|
35
|
+
|
36
|
+
# Class-wide verbosity level.
|
37
|
+
@@verbose = 0
|
38
|
+
|
39
|
+
# Setter.
|
40
|
+
def self.verbose=(val)
|
41
|
+
@@verbose = val
|
42
|
+
end
|
43
|
+
|
44
|
+
# Getter.
|
45
|
+
def self.getVerbose
|
46
|
+
@@verbose
|
47
|
+
end
|
48
|
+
|
49
|
+
# A handy check. Use it like:
|
50
|
+
#
|
51
|
+
# puts (CliUtils.debug ? "DEBUG mode" : "")
|
52
|
+
def self.debug
|
53
|
+
@@verbose >= 2
|
54
|
+
end
|
55
|
+
|
56
|
+
# A handy method that return a nicely formatted current global
|
57
|
+
# backtrace.
|
58
|
+
def self.getBacktrace
|
59
|
+
"#{$!}\n\nBacktrace:\n\n#{$!.backtrace.join("\n")}"
|
60
|
+
end
|
61
|
+
|
62
|
+
# Print an error msg & exit if exit_code > 0.
|
63
|
+
def self.errx(exit_code = 0, msg)
|
64
|
+
$stderr.puts File.basename($0) + ' error: ' + msg.to_s
|
65
|
+
exit exit_code if exit_code > 0
|
66
|
+
end
|
67
|
+
|
68
|
+
# Print a warning.
|
69
|
+
def self.warnx(msg)
|
70
|
+
$stderr.puts File.basename($0) + ' warning: ' + msg.to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
# [level] Verbosity level.
|
74
|
+
# [msg] A message to print.
|
75
|
+
#
|
76
|
+
# Don't print msg with a newline if it contains NNL_MARK at the end.
|
77
|
+
def self.veputs(level, msg)
|
78
|
+
t = msg.dup
|
79
|
+
|
80
|
+
nnl = false
|
81
|
+
if t.match(/#{NNL_MARK}$/)
|
82
|
+
t.sub!(/#{$&}/, '')
|
83
|
+
nnl = true
|
84
|
+
end
|
85
|
+
|
86
|
+
if @@verbose >= level
|
87
|
+
nnl ? print(t) : print("#{t}\n")
|
88
|
+
$stdout.flush
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Analogue to a shell command +which+.
|
93
|
+
def self.which(file)
|
94
|
+
return true if file =~ %r%\A/% and File.exist? file
|
95
|
+
|
96
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
|
97
|
+
File.exist? File.join(path, file)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Execute cmd and return an array [exit_status, stderr, stdout].
|
102
|
+
def self.exec(cmd)
|
103
|
+
so = sr = ''
|
104
|
+
status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
|
105
|
+
so = stdout.read
|
106
|
+
sr = stderr.read
|
107
|
+
}
|
108
|
+
[status.exitstatus, sr, so]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
# Don't remove this: falsework/2.0.0/ruby-cli/2012-03-05T05:04:11+02:00
|
File without changes
|
data/lib/falsework/templates/{ruby-naive/test/helper_trestle.rb → ruby-cli/test/helper_cliutils.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
|
-
# :erb:
|
1
|
+
# :erb: ruby-cli
|
2
2
|
# Various staff for minitest. Include this file into your 'helper.rb'.
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
5
|
include FileUtils
|
6
6
|
|
7
|
-
require_relative '../lib/<%= @project %>/
|
7
|
+
require_relative '../lib/<%= @project %>/cliutils'
|
8
8
|
include <%= @camelcase %>
|
9
9
|
|
10
10
|
require 'minitest/autorun'
|
@@ -22,7 +22,7 @@ def cmd(c)
|
|
22
22
|
# tests were invoked by 'gem check -t <%= @project %>'
|
23
23
|
# (for a classic rubygems 1.3.7)
|
24
24
|
begin
|
25
|
-
Dir.chdir(
|
25
|
+
Dir.chdir(CliUtils::DIR_LIB_SRC.parent.parent + test)
|
26
26
|
rescue
|
27
27
|
raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
|
28
28
|
end
|
@@ -31,4 +31,4 @@ def cmd(c)
|
|
31
31
|
File.absolute_path('../bin/' + c)
|
32
32
|
end
|
33
33
|
|
34
|
-
# Don't remove this: falsework/
|
34
|
+
# Don't remove this: falsework/2.0.0/ruby-cli/2012-03-05T05:04:11+02:00
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*-ruby-*-
|
3
|
-
# :erb:
|
3
|
+
# :erb: ruby-cli
|
4
4
|
|
5
5
|
# This is a helper for your Rakefile. Read the comments for each
|
6
6
|
# function.
|
@@ -33,4 +33,4 @@ end
|
|
33
33
|
|
34
34
|
pp git_ls('.') if __FILE__ == $0
|
35
35
|
|
36
|
-
# Don't remove this: falsework/
|
36
|
+
# Don't remove this: falsework/2.0.0/ruby-cli/2012-03-05T05:04:11+02:00
|
File without changes
|
data/test/helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'helper_cliutils'
|
@@ -1,10 +1,10 @@
|
|
1
|
-
# :erb:
|
1
|
+
# :erb: ruby-cli
|
2
2
|
# Various staff for minitest. Include this file into your 'helper.rb'.
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
5
|
include FileUtils
|
6
6
|
|
7
|
-
require_relative '../lib/falsework/
|
7
|
+
require_relative '../lib/falsework/cliutils'
|
8
8
|
include Falsework
|
9
9
|
|
10
10
|
require 'minitest/autorun'
|
@@ -22,7 +22,7 @@ def cmd(c)
|
|
22
22
|
# tests were invoked by 'gem check -t falsework'
|
23
23
|
# (for a classic rubygems 1.3.7)
|
24
24
|
begin
|
25
|
-
Dir.chdir(
|
25
|
+
Dir.chdir(CliUtils::DIR_LIB_SRC.parent.parent + test)
|
26
26
|
rescue
|
27
27
|
raise "running tests from '#{Dir.pwd}' isn't supported: #{$!}"
|
28
28
|
end
|
data/test/rake_erb_templates.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative '../lib/falsework/mould'
|
|
5
5
|
|
6
6
|
# Search for all files in the project (except .git directory) for the line
|
7
7
|
#
|
8
|
-
# /^..? :erb
|
8
|
+
# /^..? :erb: [^ ]+/
|
9
9
|
#
|
10
10
|
# in first 4 lines. If the line is found, the file is considered a
|
11
11
|
# skeleton for a template. Return a hash {target:template}
|
@@ -29,7 +29,7 @@ def erb_skeletons(local_prj, template)
|
|
29
29
|
n = 0
|
30
30
|
while n < line_max && line = fp.gets
|
31
31
|
# puts line
|
32
|
-
if line =~ /^..? :erb
|
32
|
+
if line =~ /^..? :erb: [^\s]+/
|
33
33
|
t = i.sub(/^.+?\//, '')
|
34
34
|
r[target + '/' + t.sub(/#{local_prj}/, '%%@project%%')] = t
|
35
35
|
break
|
@@ -57,4 +57,4 @@ def erb_make(local_prj, template, target, tmplt)
|
|
57
57
|
end
|
58
58
|
|
59
59
|
|
60
|
-
pp erb_skeletons(Falsework::Meta::NAME, 'ruby-
|
60
|
+
pp erb_skeletons(Falsework::Meta::NAME, 'ruby-cli') if __FILE__ == $0
|
data/test/rake_git.rb
CHANGED
data/test/test_cl.rb
CHANGED
@@ -9,20 +9,24 @@ class TestFalsework_3867654745 < MiniTest::Unit::TestCase
|
|
9
9
|
|
10
10
|
def test_listdirs
|
11
11
|
assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
|
12
|
-
out, err = capture_io { Mould.template_dirs_add ["DOESN'T EXISI"] }
|
12
|
+
out, err = capture_io { Mould.template_dirs_add [Pathname.new("DOESN'T EXISI")] }
|
13
|
+
assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
|
14
|
+
|
15
|
+
assert_raises(RuntimeError) { Mould.template_dirs_add([Dir.pwd]) }
|
13
16
|
assert_equal 2, Mould.class_variable_get(:@@template_dirs).size
|
14
|
-
Mould.template_dirs_add [Dir.pwd]
|
15
|
-
assert_equal 3, Mould.class_variable_get(:@@template_dirs).size
|
16
17
|
|
18
|
+
Mould.template_dirs_add [Pathname.new(Dir.pwd)]
|
19
|
+
assert_equal 3, Mould.class_variable_get(:@@template_dirs).size
|
20
|
+
|
17
21
|
assert_equal true, Mould.templates.key?("templates")
|
18
22
|
end
|
19
23
|
|
20
24
|
def test_new_dir_from_config
|
21
|
-
r =
|
25
|
+
r = CliUtils.exec "#{@cmd} --config /NO_SUCH_FILE.yaml listdirs"
|
22
26
|
assert_equal(0, r[0])
|
23
27
|
assert_equal(2, r[2].split("\n").size)
|
24
28
|
|
25
|
-
r =
|
29
|
+
r = CliUtils.exec "#{@cmd} --config templates/config-01.yaml listdirs"
|
26
30
|
assert_equal(0, r[0])
|
27
31
|
assert_equal(3, r[2].split("\n").size)
|
28
32
|
end
|