main 2.8.4 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +60 -77
- data/README.erb +784 -0
- data/Rakefile +241 -0
- data/lib/main.rb +1 -1
- data/lib/main/base.rb +5 -5
- data/lib/main/parameter.rb +1 -1
- data/lib/main/usage.rb +0 -3
- data/main.gemspec +28 -0
- data/test/main.rb +11 -0
- metadata +9 -28
- data/gemspec.rb +0 -36
- data/gen_readme.rb +0 -42
- data/install.rb +0 -214
data/Rakefile
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
This.author = "Ara T. Howard"
|
2
|
+
This.email = "ara.t.howard@gmail.com"
|
3
|
+
This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
|
4
|
+
This.rubyforge_project = 'codeforpeople'
|
5
|
+
|
6
|
+
task :default do
|
7
|
+
puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
|
8
|
+
end
|
9
|
+
|
10
|
+
task :spec do
|
11
|
+
require 'spec/rake/spectask'
|
12
|
+
Spec::Rake::SpecTask.new do |t|
|
13
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
task :gemspec do
|
18
|
+
ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
|
19
|
+
ignore_directories = 'pkg'
|
20
|
+
ignore_files = 'test/log'
|
21
|
+
|
22
|
+
shiteless =
|
23
|
+
lambda do |list|
|
24
|
+
list.delete_if do |entry|
|
25
|
+
next unless test(?e, entry)
|
26
|
+
extension = File.basename(entry).split(%r/[.]/).last
|
27
|
+
ignore_extensions.any?{|ext| ext === extension}
|
28
|
+
end
|
29
|
+
list.delete_if do |entry|
|
30
|
+
next unless test(?d, entry)
|
31
|
+
dirname = File.expand_path(entry)
|
32
|
+
ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
|
33
|
+
end
|
34
|
+
list.delete_if do |entry|
|
35
|
+
next unless test(?f, entry)
|
36
|
+
filename = File.expand_path(entry)
|
37
|
+
ignore_files.any?{|file| File.expand_path(file) == filename}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
lib = This.lib
|
42
|
+
version = This.version
|
43
|
+
files = shiteless[Dir::glob("**/**")]
|
44
|
+
executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
|
45
|
+
has_rdoc = true #File.exist?('doc')
|
46
|
+
test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
|
47
|
+
|
48
|
+
extensions = This.extensions
|
49
|
+
if extensions.nil?
|
50
|
+
%w( Makefile configure extconf.rb ).each do |ext|
|
51
|
+
extensions << ext if File.exists?(ext)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
extensions = [extensions].flatten.compact
|
55
|
+
|
56
|
+
template =
|
57
|
+
if test(?e, 'gemspec.erb')
|
58
|
+
Template{ IO.read('gemspec.erb') }
|
59
|
+
else
|
60
|
+
Template {
|
61
|
+
<<-__
|
62
|
+
## #{ lib }.gemspec
|
63
|
+
#
|
64
|
+
|
65
|
+
Gem::Specification::new do |spec|
|
66
|
+
spec.name = #{ lib.inspect }
|
67
|
+
spec.version = #{ version.inspect }
|
68
|
+
spec.platform = Gem::Platform::RUBY
|
69
|
+
spec.summary = #{ lib.inspect }
|
70
|
+
|
71
|
+
spec.files = #{ files.inspect }
|
72
|
+
spec.executables = #{ executables.inspect }
|
73
|
+
|
74
|
+
<% if test(?d, 'lib') %>
|
75
|
+
spec.require_path = "lib"
|
76
|
+
<% end %>
|
77
|
+
|
78
|
+
spec.has_rdoc = #{ has_rdoc.inspect }
|
79
|
+
spec.test_files = #{ test_files.inspect }
|
80
|
+
#spec.add_dependency 'lib', '>= version'
|
81
|
+
#spec.add_dependency 'fattr'
|
82
|
+
|
83
|
+
spec.extensions.push(*#{ extensions.inspect })
|
84
|
+
|
85
|
+
spec.rubyforge_project = #{ This.rubyforge_project.inspect }
|
86
|
+
spec.author = #{ This.author.inspect }
|
87
|
+
spec.email = #{ This.email.inspect }
|
88
|
+
spec.homepage = #{ This.homepage.inspect }
|
89
|
+
end
|
90
|
+
__
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
|
95
|
+
This.gemspec = "#{ lib }.gemspec"
|
96
|
+
end
|
97
|
+
|
98
|
+
task :gem => [:clean, :gemspec] do
|
99
|
+
Fu.mkdir_p This.pkgdir
|
100
|
+
before = Dir['*.gem']
|
101
|
+
cmd = "gem build #{ This.gemspec }"
|
102
|
+
`#{ cmd }`
|
103
|
+
after = Dir['*.gem']
|
104
|
+
gem = ((after - before).first || after.first) or abort('no gem!')
|
105
|
+
Fu.mv gem, This.pkgdir
|
106
|
+
This.gem = File.basename(gem)
|
107
|
+
end
|
108
|
+
|
109
|
+
task :readme do
|
110
|
+
samples = ''
|
111
|
+
prompt = '~ > '
|
112
|
+
lib = This.lib
|
113
|
+
version = This.version
|
114
|
+
|
115
|
+
Dir['sample*/*'].sort.each do |sample|
|
116
|
+
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
117
|
+
|
118
|
+
cmd = "cat #{ sample }"
|
119
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
120
|
+
samples << Util.indent(`#{ cmd }`, 4) << "\n"
|
121
|
+
|
122
|
+
cmd = "ruby #{ sample }"
|
123
|
+
samples << Util.indent(prompt + cmd, 2) << "\n\n"
|
124
|
+
|
125
|
+
cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib #{ sample })'"
|
126
|
+
samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
template =
|
130
|
+
if test(?e, 'readme.erb')
|
131
|
+
Template{ IO.read('readme.erb') }
|
132
|
+
else
|
133
|
+
Template {
|
134
|
+
<<-__
|
135
|
+
NAME
|
136
|
+
#{ lib }
|
137
|
+
|
138
|
+
DESCRIPTION
|
139
|
+
|
140
|
+
INSTALL
|
141
|
+
gem install #{ lib }
|
142
|
+
|
143
|
+
SAMPLES
|
144
|
+
#{ samples }
|
145
|
+
__
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
open("README", "w"){|fd| fd.puts template}
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
task :clean do
|
154
|
+
Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
task :release => [:clean, :gemspec, :gem] do
|
159
|
+
gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
|
160
|
+
raise "which one? : #{ gems.inspect }" if gems.size > 1
|
161
|
+
raise "no gems?" if gems.size < 1
|
162
|
+
cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
|
163
|
+
puts cmd
|
164
|
+
system cmd
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
BEGIN {
|
172
|
+
$VERBOSE = nil
|
173
|
+
|
174
|
+
require 'ostruct'
|
175
|
+
require 'erb'
|
176
|
+
require 'fileutils'
|
177
|
+
|
178
|
+
Fu = FileUtils
|
179
|
+
|
180
|
+
This = OpenStruct.new
|
181
|
+
|
182
|
+
This.file = File.expand_path(__FILE__)
|
183
|
+
This.dir = File.dirname(This.file)
|
184
|
+
This.pkgdir = File.join(This.dir, 'pkg')
|
185
|
+
|
186
|
+
lib = ENV['LIB']
|
187
|
+
unless lib
|
188
|
+
lib = File.basename(Dir.pwd)
|
189
|
+
end
|
190
|
+
This.lib = lib
|
191
|
+
|
192
|
+
version = ENV['VERSION']
|
193
|
+
unless version
|
194
|
+
name = lib.capitalize
|
195
|
+
library = "./lib/#{ lib }.rb"
|
196
|
+
program = "./bin/#{ lib }"
|
197
|
+
if test(?e, library)
|
198
|
+
require library
|
199
|
+
version = eval(name).send(:version)
|
200
|
+
elsif test(?e, program)
|
201
|
+
version = `#{ program } --version`.strip
|
202
|
+
end
|
203
|
+
abort('no version') if(version.nil? or version.empty?)
|
204
|
+
end
|
205
|
+
This.version = version
|
206
|
+
|
207
|
+
abort('no lib') unless This.lib
|
208
|
+
abort('no version') unless This.version
|
209
|
+
|
210
|
+
module Util
|
211
|
+
def indent(s, n = 2)
|
212
|
+
s = unindent(s)
|
213
|
+
ws = ' ' * n
|
214
|
+
s.gsub(%r/^/, ws)
|
215
|
+
end
|
216
|
+
|
217
|
+
def unindent(s)
|
218
|
+
indent = nil
|
219
|
+
s.each do |line|
|
220
|
+
next if line =~ %r/^\s*$/
|
221
|
+
indent = line[%r/^\s*/] and break
|
222
|
+
end
|
223
|
+
indent ? s.gsub(%r/^#{ indent }/, "") : s
|
224
|
+
end
|
225
|
+
extend self
|
226
|
+
end
|
227
|
+
|
228
|
+
class Template
|
229
|
+
def initialize(&block)
|
230
|
+
@block = block
|
231
|
+
@template = block.call.to_s
|
232
|
+
end
|
233
|
+
def expand(b=nil)
|
234
|
+
ERB.new(Util.unindent(@template)).result(b||@block)
|
235
|
+
end
|
236
|
+
alias_method 'to_s', 'expand'
|
237
|
+
end
|
238
|
+
def Template(*args, &block) Template.new(*args, &block) end
|
239
|
+
|
240
|
+
Dir.chdir(This.dir)
|
241
|
+
}
|
data/lib/main.rb
CHANGED
data/lib/main/base.rb
CHANGED
@@ -87,11 +87,11 @@ module Main
|
|
87
87
|
fattr( 'stderr' ){ $stderr }
|
88
88
|
fattr( 'logger' ){ stderr }
|
89
89
|
fattr( 'logger_level' ){ Logger::INFO }
|
90
|
-
fattr( 'exit_status' ){ EXIT_SUCCESS }
|
91
|
-
fattr( 'exit_success' ){ EXIT_SUCCESS }
|
92
|
-
fattr( 'exit_failure' ){ EXIT_FAILURE }
|
93
|
-
fattr( 'exit_warn' ){ EXIT_WARN }
|
94
|
-
inheritable_fattr( 'parameters' ){ Parameter::List[] }
|
90
|
+
fattr( 'exit_status' ){ Main::EXIT_SUCCESS }
|
91
|
+
fattr( 'exit_success' ){ Main::EXIT_SUCCESS }
|
92
|
+
fattr( 'exit_failure' ){ Main::EXIT_FAILURE }
|
93
|
+
fattr( 'exit_warn' ){ Main::EXIT_WARN }
|
94
|
+
inheritable_fattr( 'parameters' ){ Main::Parameter::List[] }
|
95
95
|
inheritable_fattr( 'can_has_hash' ){ Hash.new }
|
96
96
|
inheritable_fattr( 'mixin_table' ){ Hash.new }
|
97
97
|
|
data/lib/main/parameter.rb
CHANGED
data/lib/main/usage.rb
CHANGED
data/main.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
## main.gemspec
|
2
|
+
#
|
3
|
+
|
4
|
+
Gem::Specification::new do |spec|
|
5
|
+
spec.name = "main"
|
6
|
+
spec.version = "2.9.0"
|
7
|
+
spec.platform = Gem::Platform::RUBY
|
8
|
+
spec.summary = "main"
|
9
|
+
|
10
|
+
spec.files = ["lib", "lib/main", "lib/main/base.rb", "lib/main/cast.rb", "lib/main/factories.rb", "lib/main/getoptlong.rb", "lib/main/logger.rb", "lib/main/mode.rb", "lib/main/parameter.rb", "lib/main/softspoken.rb", "lib/main/stdext.rb", "lib/main/usage.rb", "lib/main/util.rb", "lib/main.rb", "main.gemspec", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "test", "test/main.rb", "TODO"]
|
11
|
+
spec.executables = []
|
12
|
+
|
13
|
+
|
14
|
+
spec.require_path = "lib"
|
15
|
+
|
16
|
+
|
17
|
+
spec.has_rdoc = true
|
18
|
+
spec.test_files = "test/main.rb"
|
19
|
+
#spec.add_dependency 'lib', '>= version'
|
20
|
+
#spec.add_dependency 'fattr'
|
21
|
+
|
22
|
+
spec.extensions.push(*[])
|
23
|
+
|
24
|
+
spec.rubyforge_project = "codeforpeople"
|
25
|
+
spec.author = "Ara T. Howard"
|
26
|
+
spec.email = "ara.t.howard@gmail.com"
|
27
|
+
spec.homepage = "http://github.com/ahoward/main/tree/master"
|
28
|
+
end
|
data/test/main.rb
CHANGED
@@ -467,6 +467,17 @@ class T < Test::Unit::TestCase
|
|
467
467
|
}
|
468
468
|
assert foo.value == 42
|
469
469
|
end
|
470
|
+
|
471
|
+
# parameter declaration
|
472
|
+
#
|
473
|
+
def test_0271
|
474
|
+
assert_nothing_raised{
|
475
|
+
main([]){
|
476
|
+
option('--a-sorts-first', '-b')
|
477
|
+
run{}
|
478
|
+
}
|
479
|
+
}
|
480
|
+
end
|
470
481
|
|
471
482
|
# usage
|
472
483
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: main
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
@@ -9,29 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-23 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: fattr
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.0.3
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: arrayfields
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 4.5.0
|
34
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
35
16
|
description:
|
36
17
|
email: ara.t.howard@gmail.com
|
37
18
|
executables: []
|
@@ -41,9 +22,6 @@ extensions: []
|
|
41
22
|
extra_rdoc_files: []
|
42
23
|
|
43
24
|
files:
|
44
|
-
- gemspec.rb
|
45
|
-
- gen_readme.rb
|
46
|
-
- install.rb
|
47
25
|
- lib
|
48
26
|
- lib/main
|
49
27
|
- lib/main/base.rb
|
@@ -58,7 +36,10 @@ files:
|
|
58
36
|
- lib/main/usage.rb
|
59
37
|
- lib/main/util.rb
|
60
38
|
- lib/main.rb
|
39
|
+
- main.gemspec
|
40
|
+
- Rakefile
|
61
41
|
- README
|
42
|
+
- README.erb
|
62
43
|
- samples
|
63
44
|
- samples/a.rb
|
64
45
|
- samples/b.rb
|
@@ -71,8 +52,8 @@ files:
|
|
71
52
|
- test
|
72
53
|
- test/main.rb
|
73
54
|
- TODO
|
74
|
-
has_rdoc:
|
75
|
-
homepage: http://
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/ahoward/main/tree/master
|
76
57
|
post_install_message:
|
77
58
|
rdoc_options: []
|
78
59
|
|
data/gemspec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
|
-
Gem::Specification::new do |spec|
|
6
|
-
$VERBOSE = nil
|
7
|
-
|
8
|
-
shiteless = lambda do |list|
|
9
|
-
list.delete_if do |file|
|
10
|
-
file =~ %r/\.svn/ or
|
11
|
-
file =~ %r/\.tmp/
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
spec.name = lib
|
16
|
-
spec.version = version
|
17
|
-
spec.platform = Gem::Platform::RUBY
|
18
|
-
spec.summary = lib
|
19
|
-
|
20
|
-
spec.files = shiteless[Dir::glob("**/**")]
|
21
|
-
spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
|
22
|
-
|
23
|
-
spec.require_path = "lib"
|
24
|
-
|
25
|
-
spec.has_rdoc = File::exist? "doc"
|
26
|
-
spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
|
27
|
-
spec.add_dependency 'fattr', '>= 1.0.3'
|
28
|
-
spec.add_dependency 'arrayfields', '>= 4.5.0'
|
29
|
-
|
30
|
-
spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
|
31
|
-
|
32
|
-
spec.author = "Ara T. Howard"
|
33
|
-
spec.email = "ara.t.howard@gmail.com"
|
34
|
-
spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
|
35
|
-
spec.rubyforge_project = 'codeforpeople'
|
36
|
-
end
|
data/gen_readme.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
$VERBOSE=nil
|
4
|
-
|
5
|
-
def indent s, n = 2
|
6
|
-
ws = ' ' * n
|
7
|
-
s.gsub %r/^/, ws
|
8
|
-
end
|
9
|
-
|
10
|
-
template = IO::read 'README.tmpl'
|
11
|
-
|
12
|
-
samples = ''
|
13
|
-
prompt = '~ > '
|
14
|
-
|
15
|
-
skip = %w[ e.rb f.rb ]
|
16
|
-
|
17
|
-
Dir['sample*/*'].sort.each do |sample|
|
18
|
-
next if skip.include? File.basename(sample)
|
19
|
-
|
20
|
-
samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
|
21
|
-
|
22
|
-
cmd = "cat #{ sample }"
|
23
|
-
samples << indent(prompt + cmd, 2) << "\n\n"
|
24
|
-
samples << indent(`#{ cmd }`, 4) << "\n"
|
25
|
-
|
26
|
-
cmd = "ruby #{ sample }"
|
27
|
-
samples << indent(prompt + cmd, 2) << "\n\n"
|
28
|
-
|
29
|
-
cmd = "ruby -Ilib #{ sample }"
|
30
|
-
samples << indent(`#{ cmd } 2>&1`, 4) << "\n"
|
31
|
-
|
32
|
-
cmd = "ruby #{ sample } --help"
|
33
|
-
samples << indent(prompt + cmd, 2) << "\n\n"
|
34
|
-
|
35
|
-
cmd = "ruby -Ilib #{ sample } --help"
|
36
|
-
samples << indent(`#{ cmd } 2>&1`, 4) << "\n"
|
37
|
-
end
|
38
|
-
|
39
|
-
#samples.gsub! %r/^/, ' '
|
40
|
-
|
41
|
-
readme = template.gsub %r/^\s*@samples\s*$/, samples
|
42
|
-
print readme
|