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/test/test_exe.rb
CHANGED
@@ -7,9 +7,9 @@ class TestFalsework < MiniTest::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_project_list
|
10
|
-
r =
|
10
|
+
r = CliUtils.exec "#{@cmd} list"
|
11
11
|
assert_equal(0, r[0])
|
12
|
-
assert_match(/ruby-
|
12
|
+
assert_match(/ruby-cli/, r[2])
|
13
13
|
end
|
14
14
|
|
15
15
|
# very silly analogue of "sed -i'' -E 's/foo/bar/g' file"
|
@@ -18,9 +18,9 @@ class TestFalsework < MiniTest::Unit::TestCase
|
|
18
18
|
File.open(file, 'w+') {|fp| fp.printf(o) }
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def test_project_ruby_cli
|
22
22
|
rm_rf 'templates/foo'
|
23
|
-
r =
|
23
|
+
r = CliUtils.exec "#{@cmd} new templates/foo -v"
|
24
24
|
# pp r
|
25
25
|
assert_equal(0, r[0], r)
|
26
26
|
|
@@ -44,11 +44,12 @@ class TestFalsework < MiniTest::Unit::TestCase
|
|
44
44
|
"templates/foo/etc/foo.yaml",
|
45
45
|
"templates/foo/lib",
|
46
46
|
"templates/foo/lib/foo",
|
47
|
+
"templates/foo/lib/foo/cliconfig.rb",
|
48
|
+
"templates/foo/lib/foo/cliutils.rb",
|
47
49
|
"templates/foo/lib/foo/meta.rb",
|
48
|
-
"templates/foo/lib/foo/trestle.rb",
|
49
50
|
"templates/foo/test",
|
50
51
|
"templates/foo/test/helper.rb",
|
51
|
-
"templates/foo/test/
|
52
|
+
"templates/foo/test/helper_cliutils.rb",
|
52
53
|
"templates/foo/test/rake_git.rb",
|
53
54
|
"templates/foo/test/test_foo.rb"]
|
54
55
|
|
@@ -59,67 +60,71 @@ class TestFalsework < MiniTest::Unit::TestCase
|
|
59
60
|
|
60
61
|
Dir.chdir('templates/foo') {
|
61
62
|
# add files
|
62
|
-
r =
|
63
|
+
r = CliUtils.exec "#{@cmd} exe qqq"
|
63
64
|
assert_equal(0, r[0])
|
64
65
|
assert_equal(true, File.executable?('bin/qqq'))
|
65
66
|
assert_equal(true, File.exist?('doc/qqq.rdoc'))
|
67
|
+
# smoke test of generated exe
|
68
|
+
r = CliUtils.exec "bin/qqq --version"
|
69
|
+
assert_equal 0, r[0]
|
70
|
+
assert_equal "0.0.1\n", r[2]
|
66
71
|
|
67
|
-
r =
|
72
|
+
r = CliUtils.exec "#{@cmd} test qqq"
|
68
73
|
assert_equal(0, r[0])
|
69
74
|
assert_equal(true, File.exist?('test/test_qqq.rb'))
|
70
75
|
|
71
76
|
# upgrade
|
72
|
-
r =
|
77
|
+
r = CliUtils.exec "#{@cmd} upgrade -b"
|
73
78
|
assert_equal(0, r[0])
|
74
|
-
rm ['test/
|
75
|
-
r =
|
79
|
+
rm ['test/helper_cliutils.rb', 'test/rake_git.rb']
|
80
|
+
r = CliUtils.exec "#{@cmd} upgrade -b"
|
76
81
|
assert_equal(0, r[0])
|
77
|
-
sed 'test/
|
82
|
+
sed 'test/helper_cliutils.rb',
|
78
83
|
/^(# Don't.+falsework\/)\d+\.\d+\.\d+(\/.+)$/, '\1999.999.999\2'
|
79
|
-
r =
|
84
|
+
r = CliUtils.exec "#{@cmd} upgrade -b"
|
80
85
|
assert_equal(1, r[0])
|
81
86
|
assert_match(/file .+ is from .+ falsework: 999.999.999/, r[1])
|
82
87
|
mv('test', 'ttt')
|
83
|
-
r =
|
88
|
+
r = CliUtils.exec "#{@cmd} upgrade -b"
|
84
89
|
assert_equal(0, r[0])
|
85
90
|
}
|
86
91
|
end
|
87
92
|
|
88
93
|
def test_project_invalid_name
|
89
|
-
r =
|
94
|
+
r = CliUtils.exec "#{@cmd} new 123"
|
90
95
|
assert_equal(1, r[0])
|
91
96
|
assert_match(/invalid project name/, r[1])
|
92
97
|
end
|
93
98
|
|
94
99
|
def test_project_c_glib
|
95
100
|
rm_rf 'templates/c_glib'
|
96
|
-
r =
|
101
|
+
r = CliUtils.exec "#{@cmd} new templates/c-glib -t c-glib --no-git"
|
97
102
|
assert_equal(0, r[0])
|
98
103
|
|
99
104
|
Dir.chdir('templates/c_glib') {
|
100
|
-
r =
|
105
|
+
r = CliUtils.exec "#{@cmd} -t c-glib exe q-q-q"
|
101
106
|
assert_equal(0, r[0])
|
102
107
|
assert_equal(true, File.exist?('src/q_q_q.h'))
|
103
108
|
assert_equal(true, File.exist?('src/q_q_q.c'))
|
104
109
|
assert_equal(true, File.exist?('doc/q_q_q.1.asciidoc'))
|
105
110
|
|
106
|
-
r =
|
111
|
+
r = CliUtils.exec "#{@cmd} -t c-glib test q-q-q"
|
107
112
|
assert_equal(0, r[0])
|
108
113
|
assert_equal(true, File.exist?('test/test_q_q_q.c'))
|
109
114
|
|
110
115
|
Dir.chdir('src') {
|
111
|
-
r =
|
116
|
+
r = CliUtils.exec "gmake"
|
112
117
|
assert_equal 0, r[0]
|
113
118
|
assert_equal true, File.executable?('c_glib')
|
114
119
|
assert_equal(true, File.exist?('q_q_q.o'))
|
115
120
|
}
|
116
121
|
Dir.chdir('test') {
|
117
|
-
r =
|
122
|
+
r = CliUtils.exec "gmake"
|
118
123
|
assert_equal 0, r[0]
|
119
124
|
assert_equal true, File.executable?('test_utils')
|
120
125
|
assert_equal true, File.executable?('test_q_q_q')
|
121
126
|
|
122
|
-
r =
|
127
|
+
r = CliUtils.exec "gmake test"
|
123
128
|
assert_equal 0, r[0]
|
124
129
|
}
|
125
130
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: falsework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: git
|
16
|
-
requirement: &
|
16
|
+
requirement: &74400880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,18 +21,18 @@ dependencies:
|
|
21
21
|
version: 1.2.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *74400880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: open4
|
27
|
-
requirement: &
|
27
|
+
requirement: &74400650 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *74400650
|
36
36
|
description: A primitive scaffold generator for writing CLI programs in Ruby.
|
37
37
|
email: alexander.gromnitsky@gmail.com
|
38
38
|
executables:
|
@@ -56,6 +56,8 @@ files:
|
|
56
56
|
- doc/TODO.org
|
57
57
|
- doc/template-tutorial.rdoc
|
58
58
|
- etc/falsework.yaml
|
59
|
+
- lib/falsework/cliconfig.rb
|
60
|
+
- lib/falsework/cliutils.rb
|
59
61
|
- lib/falsework/meta.rb
|
60
62
|
- lib/falsework/mould.rb
|
61
63
|
- lib/falsework/templates/c-glib/#config.yaml
|
@@ -79,38 +81,41 @@ files:
|
|
79
81
|
- lib/falsework/templates/c-glib/test/mycat.c
|
80
82
|
- lib/falsework/templates/c-glib/test/semis/text/empty.txt
|
81
83
|
- lib/falsework/templates/c-glib/test/test_utils.c
|
82
|
-
- lib/falsework/templates/ruby-
|
83
|
-
- lib/falsework/templates/ruby-
|
84
|
-
- lib/falsework/templates/ruby-
|
85
|
-
- lib/falsework/templates/ruby-
|
86
|
-
- lib/falsework/templates/ruby-
|
87
|
-
- lib/falsework/templates/ruby-
|
88
|
-
- lib/falsework/templates/ruby-
|
89
|
-
- lib/falsework/templates/ruby-
|
90
|
-
- lib/falsework/templates/ruby-
|
91
|
-
- lib/falsework/templates/ruby-
|
92
|
-
- lib/falsework/templates/ruby-
|
93
|
-
- lib/falsework/templates/ruby-
|
94
|
-
- lib/falsework/templates/ruby-
|
95
|
-
- lib/falsework/templates/ruby-
|
96
|
-
- lib/falsework/trestle.rb
|
84
|
+
- lib/falsework/templates/ruby-cli/#config.yaml
|
85
|
+
- lib/falsework/templates/ruby-cli/.gitignore.#erb
|
86
|
+
- lib/falsework/templates/ruby-cli/Gemfile
|
87
|
+
- lib/falsework/templates/ruby-cli/README.rdoc
|
88
|
+
- lib/falsework/templates/ruby-cli/Rakefile
|
89
|
+
- lib/falsework/templates/ruby-cli/bin/%%@project%%
|
90
|
+
- lib/falsework/templates/ruby-cli/doc/#doc.rdoc
|
91
|
+
- lib/falsework/templates/ruby-cli/doc/LICENSE
|
92
|
+
- lib/falsework/templates/ruby-cli/doc/NEWS.rdoc
|
93
|
+
- lib/falsework/templates/ruby-cli/doc/README.rdoc
|
94
|
+
- lib/falsework/templates/ruby-cli/etc/%%@project%%.yaml
|
95
|
+
- lib/falsework/templates/ruby-cli/lib/%%@project%%/meta.rb
|
96
|
+
- lib/falsework/templates/ruby-cli/test/helper.rb
|
97
|
+
- lib/falsework/templates/ruby-cli/test/test_%%@project%%.rb
|
97
98
|
- test/helper.rb
|
98
|
-
- test/
|
99
|
+
- test/helper_cliutils.rb
|
99
100
|
- test/rake_erb_templates.rb
|
100
101
|
- test/rake_git.rb
|
101
102
|
- test/templates/config-01.yaml
|
103
|
+
- test/templates/config-02.yaml
|
102
104
|
- test/test_cl.rb
|
103
105
|
- test/test_exe.rb
|
104
106
|
- test/test_mould.rb
|
105
|
-
- lib/falsework/templates/ruby-
|
106
|
-
- lib/falsework/templates/ruby-
|
107
|
-
- lib/falsework/templates/ruby-
|
107
|
+
- lib/falsework/templates/ruby-cli/lib/%%@project%%/cliconfig.rb
|
108
|
+
- lib/falsework/templates/ruby-cli/lib/%%@project%%/cliutils.rb
|
109
|
+
- lib/falsework/templates/ruby-cli/test/helper_cliutils.rb
|
110
|
+
- lib/falsework/templates/ruby-cli/test/rake_git.rb
|
108
111
|
homepage: http://github.com/gromnitsky/falsework
|
109
112
|
licenses: []
|
110
113
|
post_install_message:
|
111
114
|
rdoc_options:
|
112
115
|
- -m
|
113
116
|
- doc/README.rdoc
|
117
|
+
- -x
|
118
|
+
- lib/.+/templates/
|
114
119
|
require_paths:
|
115
120
|
- lib
|
116
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*-ruby-*-
|
3
|
-
|
4
|
-
require_relative '../lib/<%= @project %>/trestle.rb'
|
5
|
-
|
6
|
-
include <%= @camelcase %>
|
7
|
-
|
8
|
-
$conf = Hash.new
|
9
|
-
$t = Trestle.new($conf)
|
10
|
-
|
11
|
-
$conf[:banner] = "Usage: #{File.basename($0)} [options] hren'"
|
12
|
-
$conf[:foobar] = ''
|
13
|
-
|
14
|
-
|
15
|
-
# --[ main ]------------------------------------------------------------
|
16
|
-
|
17
|
-
$t.config_parse(['foobar']) {|src|
|
18
|
-
o = $t.cl_parse(src) # create an OptionParser object
|
19
|
-
o.on('--foobar STR', 'An example of the option --foobar') {|i|
|
20
|
-
$conf[:foobar] = i
|
21
|
-
}
|
22
|
-
$t.cl_parse(src, o) # run cl parser
|
23
|
-
}
|
24
|
-
|
25
|
-
# print our env
|
26
|
-
if $conf[:verbose] >= 2
|
27
|
-
puts 'Libs dir: ' + Trestle.gem_libdir
|
28
|
-
pp $conf
|
29
|
-
end
|
30
|
-
|
31
|
-
puts 'Hello, World!'
|
@@ -1,230 +0,0 @@
|
|
1
|
-
# :erb:
|
2
|
-
require 'yaml'
|
3
|
-
require 'shellwords.rb'
|
4
|
-
require 'optparse'
|
5
|
-
require 'pp'
|
6
|
-
require 'open4'
|
7
|
-
|
8
|
-
require_relative 'meta'
|
9
|
-
|
10
|
-
module <%= @camelcase %>
|
11
|
-
# A common routines from <%= @project %> with love.
|
12
|
-
class Trestle
|
13
|
-
|
14
|
-
# Execute _cmd_ and return a list [exit_status, stderr,
|
15
|
-
# stdout]. Very handy.
|
16
|
-
def self.cmd_run(cmd)
|
17
|
-
so = sr = ''
|
18
|
-
status = Open4::popen4(cmd) { |pid, stdin, stdout, stderr|
|
19
|
-
so = stdout.read
|
20
|
-
sr = stderr.read
|
21
|
-
}
|
22
|
-
[status.exitstatus, sr, so]
|
23
|
-
end
|
24
|
-
|
25
|
-
# Return a directory with program libraries.
|
26
|
-
def self.gem_libdir
|
27
|
-
t = ["#{File.dirname(File.realpath($0))}/../lib/#{<%= @camelcase %>::Meta::NAME}",
|
28
|
-
"#{Gem.dir}/gems/#{<%= @camelcase %>::Meta::NAME}-#{<%= @camelcase %>::Meta::VERSION}/lib/#{<%= @camelcase %>::Meta::NAME}",
|
29
|
-
"lib/#{<%= @camelcase %>::Meta::NAME}"]
|
30
|
-
t.each {|i| return i if File.readable?(i) }
|
31
|
-
fail "all paths are invalid: #{t}"
|
32
|
-
end
|
33
|
-
|
34
|
-
# Analogue to shell command +which+.
|
35
|
-
def self.in_path?(file)
|
36
|
-
return true if file =~ %r%\A/% and File.exist? file
|
37
|
-
|
38
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).any? do |path|
|
39
|
-
File.exist? File.join(path, file)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Print an error message _t_ and exit if _ec_ > 0.
|
44
|
-
def self.errx(ec, t)
|
45
|
-
$stderr.puts File.basename($0) + ' error: ' + t.to_s
|
46
|
-
exit ec if ec > 0
|
47
|
-
end
|
48
|
-
|
49
|
-
# Print a warning.
|
50
|
-
def self.warnx(t)
|
51
|
-
$stderr.puts File.basename($0) + ' warning: ' + t.to_s
|
52
|
-
end
|
53
|
-
|
54
|
-
# #veputs uses this to decide to put a newline or not to put.
|
55
|
-
NNL_MARK = '__NNL__'
|
56
|
-
|
57
|
-
# Use this in your CL options to check if modifying some variable is
|
58
|
-
# not an idempotent act.
|
59
|
-
attr_reader :cl_opt_protect
|
60
|
-
|
61
|
-
# [conf] Typically must be a reference to some global variable.
|
62
|
-
def initialize(conf)
|
63
|
-
@conf = conf
|
64
|
-
@conf[:verbose] = 0
|
65
|
-
@conf[:banner] = "Usage: #{File.basename($0)} [options]"
|
66
|
-
@conf[:config] = Meta::NAME + '.yaml'
|
67
|
-
@conf[:config_dirs] = [ENV['HOME']+'/.'+Meta::NAME,
|
68
|
-
File.absolute_path("#{File.dirname(File.realpath($0))}/../etc"),
|
69
|
-
'/usr/etc', '/usr/local/etc', '/etc',
|
70
|
-
"#{Gem.dir}/gems/#{Meta::NAME}-#{Meta::VERSION}/etc"
|
71
|
-
]
|
72
|
-
@conf[:config_env] = [Meta::NAME.upcase + '_CONF']
|
73
|
-
|
74
|
-
@cl_parsing_times = 0 # not used
|
75
|
-
@cl_opt_protect = false
|
76
|
-
end
|
77
|
-
|
78
|
-
# [level] A verbose level.
|
79
|
-
# [t] A string to print.
|
80
|
-
#
|
81
|
-
# Don't print _t_ with a newline if it contains NNL_MARK at the end.
|
82
|
-
def veputs(level, t)
|
83
|
-
t = t.dup
|
84
|
-
nnl = nil
|
85
|
-
if t.match(/#{NNL_MARK}$/)
|
86
|
-
t.sub!(/#{$&}/, '')
|
87
|
-
nnl = 1
|
88
|
-
end
|
89
|
-
|
90
|
-
if @conf[:verbose] >= level
|
91
|
-
nnl ? print(t) : print("#{t}\n")
|
92
|
-
$stdout.flush
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Run all configuration parsing in a batch.
|
97
|
-
#
|
98
|
-
# [rvars] A list of variable names which must be in the
|
99
|
-
# configuration file.
|
100
|
-
#
|
101
|
-
# If no block is given, only standard CL options will be analysed.
|
102
|
-
def config_parse(rvars, &block)
|
103
|
-
cb = ->(b, src) {
|
104
|
-
if b
|
105
|
-
block.call src
|
106
|
-
else
|
107
|
-
# very basic default options
|
108
|
-
cl_parse(src, nil, true)
|
109
|
-
end
|
110
|
-
}
|
111
|
-
|
112
|
-
# 1. parse env
|
113
|
-
@conf[:config_env].each {|i|
|
114
|
-
# puts '0 run:'
|
115
|
-
cb.call(block_given?, ENV[i].shellsplit) if ENV.key?(i)
|
116
|
-
}
|
117
|
-
|
118
|
-
# 2. parse CL in case of '--config' option
|
119
|
-
# puts "\n1 run"
|
120
|
-
@cl_opt_protect = true
|
121
|
-
cb.call(block_given?, ARGV.dup)
|
122
|
-
@cl_opt_protect = false
|
123
|
-
|
124
|
-
# 3. load the configuration file & do the final CL parsing
|
125
|
-
begin
|
126
|
-
# puts "\n2 run"
|
127
|
-
r = config_flat_load(rvars)
|
128
|
-
rescue
|
129
|
-
Trestle.errx(1, "cannot load config: #{Trestle.get_backtrace}")
|
130
|
-
end
|
131
|
-
veputs(1, "OK") if r
|
132
|
-
cb.call(block_given?, ARGV)
|
133
|
-
end
|
134
|
-
|
135
|
-
# Load a config file immediately if it contains '/' in its name,
|
136
|
-
# otherwise search through several dirs for it.
|
137
|
-
#
|
138
|
-
# [rvars] a list of requied variables in the config
|
139
|
-
#
|
140
|
-
# Return a loaded filename or nil on error.
|
141
|
-
def config_flat_load(rvars)
|
142
|
-
p = ->(f) {
|
143
|
-
veputs(1, "Loading #{f}... " + NNL_MARK)
|
144
|
-
if File.file?(f)
|
145
|
-
begin
|
146
|
-
myconf = YAML.load_file(f)
|
147
|
-
rescue
|
148
|
-
abort("cannot parse #{f}: #{$!}")
|
149
|
-
end
|
150
|
-
rvars.each { |i|
|
151
|
-
fail "missing or nil '#{i}' in #{f}" if ! myconf.key?(i.to_sym) || ! myconf[i.to_sym]
|
152
|
-
}
|
153
|
-
@conf.merge!(myconf)
|
154
|
-
return @conf[:config]
|
155
|
-
end
|
156
|
-
|
157
|
-
veputs(1, "FAILED")
|
158
|
-
return nil
|
159
|
-
}
|
160
|
-
|
161
|
-
if @conf[:config].index('/')
|
162
|
-
return p.call(@conf[:config])
|
163
|
-
else
|
164
|
-
@conf[:config_dirs].each {|dir|
|
165
|
-
return dir+'/'+@conf[:config] if p.call(dir + '/' + @conf[:config])
|
166
|
-
}
|
167
|
-
end
|
168
|
-
|
169
|
-
return nil
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
# Parses CL-like options.
|
174
|
-
#
|
175
|
-
# [src] An array of options (usually +ARGV+).
|
176
|
-
#
|
177
|
-
# If _o_ is non nil function parses _src_ immediately, otherwise it
|
178
|
-
# only creates +OptionParser+ object and return it (if _simple_ is
|
179
|
-
# false).
|
180
|
-
def cl_parse(src, o = nil, simple = false)
|
181
|
-
if ! o then
|
182
|
-
# puts "NEW o (#{cl_opt_protect})" + src.to_s
|
183
|
-
o = OptionParser.new
|
184
|
-
o.banner = @conf[:banner]
|
185
|
-
o.on('-v', 'Be more verbose.') { |i|
|
186
|
-
# puts "cl_parsing_times "+cl_parsing_times.to_s
|
187
|
-
@conf[:verbose] += 1 unless cl_opt_protect
|
188
|
-
}
|
189
|
-
o.on('-V', 'Show version & exit.') { |i|
|
190
|
-
puts Meta::VERSION
|
191
|
-
exit 0
|
192
|
-
}
|
193
|
-
o.on('--config NAME', "Set a config name (default is #{@conf[:config]}).") {|i|
|
194
|
-
@conf[:config] = i
|
195
|
-
}
|
196
|
-
o.on('--config-dirs', 'Show possible config locations.') {
|
197
|
-
mark = false
|
198
|
-
@conf[:config_dirs].each { |idx|
|
199
|
-
f = idx + '/' + @conf[:config]
|
200
|
-
if File.readable?(f) && !mark
|
201
|
-
puts "* " + f
|
202
|
-
mark = true
|
203
|
-
else
|
204
|
-
puts " " + f
|
205
|
-
end
|
206
|
-
}
|
207
|
-
exit 0
|
208
|
-
}
|
209
|
-
|
210
|
-
return o if ! simple
|
211
|
-
end
|
212
|
-
|
213
|
-
begin
|
214
|
-
o.parse!(src)
|
215
|
-
@cl_parsing_times += 1
|
216
|
-
rescue
|
217
|
-
Trestle.errx(1, $!.to_s)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
# A handy proc that return a nice formatted current global
|
222
|
-
# backtrace.
|
223
|
-
def self.get_backtrace
|
224
|
-
"#{$!}\n\nBacktrace:\n\n#{$!.backtrace.join("\n")}"
|
225
|
-
end
|
226
|
-
|
227
|
-
end # trestle
|
228
|
-
end
|
229
|
-
|
230
|
-
# Don't remove this: falsework/1.3.0/ruby-naive/2012-01-27T02:39:48+02:00
|