hen 0.0.6.166 → 0.0.6.183
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/hen +42 -29
- data/lib/hen.rb +34 -17
- data/lib/hen/cli.rb +5 -5
- data/lib/hen/dsl.rb +16 -4
- data/lib/hens/gem.rake +4 -2
- data/lib/hens/rdoc.rake +1 -0
- data/lib/hens/spec.rake +2 -0
- data/lib/hens/test.rake +2 -0
- metadata +7 -7
data/Rakefile
CHANGED
@@ -13,6 +13,6 @@ Hen.lay! {{
|
|
13
13
|
"helper that fits my own personal style.",
|
14
14
|
:files => FileList['lib/**/*.rb', 'bin/*'].to_a,
|
15
15
|
:extra_files => FileList['[A-Z]*', 'lib/hens/*.rake', 'example/*', 'example/.henrc'].to_a,
|
16
|
-
:dependencies => ['rubyforge', ['ruby-nuggets', '>= 0.0.
|
16
|
+
:dependencies => ['rubyforge', ['ruby-nuggets', '>= 0.0.4']]
|
17
17
|
}
|
18
18
|
}}
|
data/bin/hen
CHANGED
@@ -28,7 +28,10 @@
|
|
28
28
|
###############################################################################
|
29
29
|
#++
|
30
30
|
|
31
|
-
# TODO:
|
31
|
+
# TODO: Implement 'list' action -- List available hens with their tasks (?)
|
32
|
+
|
33
|
+
require 'rubygems'
|
34
|
+
require 'nuggets/enumerable/minmax'
|
32
35
|
|
33
36
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
34
37
|
|
@@ -38,13 +41,17 @@ require 'hen/cli'
|
|
38
41
|
include Hen::CLI
|
39
42
|
|
40
43
|
ACTIONS = {
|
41
|
-
'config'
|
42
|
-
'create'
|
43
|
-
|
44
|
+
'config' => 'Create a fresh .henrc file',
|
45
|
+
'create' => [
|
46
|
+
'Create a new project directory tree',
|
47
|
+
'Arguments: path [sample-skeleton]'
|
48
|
+
],
|
49
|
+
'list' => 'List available hens with their tasks',
|
50
|
+
'version' => 'Display version number'
|
44
51
|
}
|
45
52
|
|
46
53
|
USAGE = <<EOT
|
47
|
-
Usage: #{$0} {#{ACTIONS.keys.sort.join('|')}}
|
54
|
+
Usage: #{$0} {#{ACTIONS.keys.sort.join('|')}} [action-arguments]
|
48
55
|
#{$0} [-h|--help]
|
49
56
|
EOT
|
50
57
|
|
@@ -58,27 +65,29 @@ case action = ARGV.shift
|
|
58
65
|
puts
|
59
66
|
puts 'Actions:'
|
60
67
|
|
61
|
-
|
68
|
+
max = ACTIONS.keys.max(:length)
|
69
|
+
|
70
|
+
ACTIONS.sort.each { |act, desc|
|
71
|
+
desc = [*desc]
|
72
|
+
puts " %-#{max}s - %s" % [act, desc.shift]
|
62
73
|
|
63
|
-
|
64
|
-
|
74
|
+
desc.each { |extra|
|
75
|
+
puts " %#{max}s + %s" % [' ', extra]
|
76
|
+
}
|
65
77
|
}
|
78
|
+
when 'version', '--version'
|
79
|
+
puts "hen v#{Hen::VERSION}"
|
66
80
|
when 'config'
|
67
|
-
|
68
|
-
|
69
|
-
# TODO: DRY up with lib/hen.rb
|
70
|
-
target = File.join(ENV['HOME'] || File.expand_path('~'), '.henrc')
|
71
|
-
|
72
|
-
render(henrc, target)
|
81
|
+
render(File.join(EXAMPLE, '.henrc'), henrc = Hen.henrc(false))
|
73
82
|
|
74
83
|
puts
|
75
|
-
puts "Your .henrc has been created: #{
|
84
|
+
puts "Your .henrc has been created: #{henrc}. Now modify it to your needs."
|
76
85
|
when 'create'
|
77
86
|
path = File.expand_path(ARGV.shift)
|
78
87
|
abort 'Path argument missing!' unless path
|
79
88
|
|
80
|
-
|
81
|
-
abort "Sample project tree not found: #{
|
89
|
+
skel = ARGV.shift || File.join(EXAMPLE, 'project')
|
90
|
+
abort "Sample project tree not found: #{skel}" unless File.directory?(skel)
|
82
91
|
|
83
92
|
if File.directory?(path)
|
84
93
|
abort "Target directory already exists: #{path}. Won't touch."
|
@@ -87,15 +96,17 @@ case action = ARGV.shift
|
|
87
96
|
end
|
88
97
|
|
89
98
|
# Parts to be replaced by the user
|
90
|
-
|
99
|
+
replace = {}
|
91
100
|
|
92
101
|
begin
|
93
102
|
# Keep track of what's been created
|
94
103
|
created = [path]
|
95
104
|
|
96
|
-
|
105
|
+
# We need the name here so ask for it already. Additionally, it's
|
106
|
+
# a good opportunity to make sure the user's .henrc is available.
|
107
|
+
progname = ask!("Program's name", true)
|
97
108
|
|
98
|
-
Dir.chdir(
|
109
|
+
Dir.chdir(skel) {
|
99
110
|
Dir['**/*'].each { |sample|
|
100
111
|
target = File.join(path, sample.gsub(/__progname__/, progname))
|
101
112
|
created << target
|
@@ -103,8 +114,7 @@ case action = ARGV.shift
|
|
103
114
|
if File.directory?(sample)
|
104
115
|
Dir.mkdir(target)
|
105
116
|
else
|
106
|
-
|
107
|
-
replacements[target] = content.scan(/### .* ###/)
|
117
|
+
replace[target] = render(sample, target).scan(/### .* ###/)
|
108
118
|
end
|
109
119
|
}
|
110
120
|
}
|
@@ -113,25 +123,28 @@ case action = ARGV.shift
|
|
113
123
|
created.clear
|
114
124
|
ensure
|
115
125
|
# In case of an exception or premature program exit: Clean up!
|
116
|
-
created.reverse.each { |
|
117
|
-
(File.directory?(
|
126
|
+
created.reverse.each { |p|
|
127
|
+
(File.directory?(p) ? Dir : File).unlink(p) if File.readable?(p)
|
118
128
|
}
|
119
129
|
end
|
120
130
|
|
121
131
|
puts
|
122
|
-
puts "Your new project directory has been created: #{path}"
|
132
|
+
puts "Your new project directory has been created: #{path}. Have fun!"
|
123
133
|
|
124
|
-
|
125
|
-
next if
|
134
|
+
replace.each { |target, details|
|
135
|
+
next if details.empty?
|
126
136
|
|
127
137
|
puts
|
128
138
|
puts "#{target}:"
|
129
139
|
|
130
|
-
|
131
|
-
puts " #{
|
140
|
+
details.each { |detail|
|
141
|
+
puts " #{detail}"
|
132
142
|
}
|
133
143
|
}
|
134
144
|
when 'list'
|
145
|
+
# How to achieve? Has to list *all* hens and tasks made available therein,
|
146
|
+
# *regardless* of any missing prerequisites (preferably indicating whether
|
147
|
+
# a particular hen/task is currently available).
|
135
148
|
abort 'Sorry, not yet available...'
|
136
149
|
else
|
137
150
|
abort "Illegal action: #{action}\n#{USAGE}"
|
data/lib/hen.rb
CHANGED
@@ -93,7 +93,13 @@ class Hen
|
|
93
93
|
# Execute each hen definition
|
94
94
|
hens.each { |name, hen|
|
95
95
|
# Load any dependencies, in case they're not included yet
|
96
|
-
|
96
|
+
begin
|
97
|
+
load_hens(*hen.dependencies)
|
98
|
+
rescue LoadError => err
|
99
|
+
warn "#{name}: Required dependency missing: " <<
|
100
|
+
File.basename(err.to_s, '.rake') if verbose
|
101
|
+
next
|
102
|
+
end
|
97
103
|
|
98
104
|
hen.lay!
|
99
105
|
}
|
@@ -124,19 +130,8 @@ class Hen
|
|
124
130
|
# henrc => aString
|
125
131
|
#
|
126
132
|
# The path to the user's .henrc
|
127
|
-
def henrc
|
128
|
-
@henrc ||=
|
129
|
-
abort "The specified .henrc file could not be found: #{henrc}" \
|
130
|
-
unless File.readable?(henrc)
|
131
|
-
|
132
|
-
henrc
|
133
|
-
else
|
134
|
-
RCDIRS.find { |path|
|
135
|
-
henrc = File.join(path, '.henrc')
|
136
|
-
break henrc if File.readable?(henrc)
|
137
|
-
} or abort "No .henrc file could be found! Please " <<
|
138
|
-
"create one first by running 'hen config'."
|
139
|
-
end
|
133
|
+
def henrc(must_exist = true)
|
134
|
+
@henrc ||= find_henrc(must_exist)
|
140
135
|
end
|
141
136
|
|
142
137
|
# call-seq:
|
@@ -149,10 +144,9 @@ class Hen
|
|
149
144
|
#
|
150
145
|
# Example:
|
151
146
|
# config('a/b/c') #=> @config[:a][:b][:c]
|
152
|
-
def config(key =
|
147
|
+
def config(key = nil)
|
153
148
|
@config ||= YAML.load_file(henrc)
|
154
|
-
|
155
|
-
return @config if key == default
|
149
|
+
return @config unless key
|
156
150
|
|
157
151
|
key.split('/').inject(@config) { |value, k|
|
158
152
|
value.fetch(k.to_sym)
|
@@ -162,6 +156,29 @@ class Hen
|
|
162
156
|
|
163
157
|
private
|
164
158
|
|
159
|
+
# call-seq:
|
160
|
+
# find_henrc(must_exist = true) => aString
|
161
|
+
#
|
162
|
+
# Search for a readable .henrc, or, if +must_exist+ is false, just return a
|
163
|
+
# suitable default location.
|
164
|
+
def find_henrc(must_exist = true)
|
165
|
+
return ENV['HENRC'] || File.join(RCDIRS.last, '.henrc') unless must_exist
|
166
|
+
|
167
|
+
if henrc = ENV['HENRC']
|
168
|
+
abort "The specified .henrc file could not be found: #{henrc}" \
|
169
|
+
unless File.readable?(henrc)
|
170
|
+
elsif henrc = RCDIRS.find { |p|
|
171
|
+
h = File.join(p, '.henrc')
|
172
|
+
break h if File.readable?(h)
|
173
|
+
}
|
174
|
+
else
|
175
|
+
abort "No .henrc file could be found! Please " <<
|
176
|
+
"create one first by running 'hen config'."
|
177
|
+
end
|
178
|
+
|
179
|
+
henrc
|
180
|
+
end
|
181
|
+
|
165
182
|
# call-seq:
|
166
183
|
# load_hens(*hens)
|
167
184
|
# load_hens(*hens) { |hen_name| ... }
|
data/lib/hen/cli.rb
CHANGED
@@ -40,17 +40,17 @@ module Hen::CLI
|
|
40
40
|
|
41
41
|
# Ask the user to enter an appropriate value for +key+. Uses
|
42
42
|
# already stored answer if present, unless +cached+ is false.
|
43
|
-
def ask(key, config_key =
|
43
|
+
def ask(key, config_key = nil, cached = true)
|
44
44
|
@@values[key] = nil unless cached
|
45
45
|
|
46
|
-
@@values[key] ||=
|
47
|
-
|
46
|
+
@@values[key] ||= config_key && Hen.config(config_key) ||
|
47
|
+
original_ask("Please enter your #{key}: ")
|
48
48
|
rescue Interrupt
|
49
49
|
abort ''
|
50
50
|
end
|
51
51
|
|
52
|
-
# Same as ask, but requires a non-empty value to be entered.
|
53
|
-
def ask!(key, config_key =
|
52
|
+
# Same as #ask, but requires a non-empty value to be entered.
|
53
|
+
def ask!(key, config_key = nil)
|
54
54
|
msg = "#{key} is required! Please enter a non-empty value."
|
55
55
|
max = 3
|
56
56
|
|
data/lib/hen/dsl.rb
CHANGED
@@ -73,7 +73,7 @@ class Hen
|
|
73
73
|
# Prepare the use of Rubyforge, optionally logging in right away.
|
74
74
|
# Returns the RubyForge object.
|
75
75
|
def init_rubyforge(login = true)
|
76
|
-
|
76
|
+
require_rubyforge
|
77
77
|
|
78
78
|
rf = RubyForge.new
|
79
79
|
rf.login if login
|
@@ -90,12 +90,12 @@ class Hen
|
|
90
90
|
rf_project = rf_config[:project]
|
91
91
|
|
92
92
|
raise 'Skipping Rubyforge tasks' if rf_project.nil? || rf_project.empty?
|
93
|
-
raise LocalJumpError, 'no block given' unless block
|
94
93
|
|
95
|
-
|
94
|
+
require_rubyforge
|
96
95
|
|
97
|
-
|
96
|
+
raise LocalJumpError, 'no block given' unless block
|
98
97
|
|
98
|
+
block_args = [rf_config]
|
99
99
|
block_args << lambda { |*args|
|
100
100
|
init_rubyforge(args.empty? || args.first)
|
101
101
|
} if block.arity > 1
|
@@ -103,6 +103,18 @@ class Hen
|
|
103
103
|
block[*block_args]
|
104
104
|
end
|
105
105
|
|
106
|
+
private
|
107
|
+
|
108
|
+
# Loads the Rubyforge library, giving a
|
109
|
+
# nicer error message if it's not found.
|
110
|
+
def require_rubyforge
|
111
|
+
begin
|
112
|
+
require 'rubyforge'
|
113
|
+
rescue LoadError
|
114
|
+
raise "Please install the 'rubyforge' gem first."
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
106
118
|
end
|
107
119
|
|
108
120
|
end
|
data/lib/hens/gem.rake
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
# Use RDOC_OPTIONS from 'rdoc.rake'
|
2
1
|
Hen :gem => :rdoc do
|
2
|
+
# Dependencies:
|
3
|
+
# * rdoc -- Uses RDOC_OPTIONS and 'publish_docs' task
|
4
|
+
|
3
5
|
require 'rake/gempackagetask'
|
4
6
|
|
5
7
|
gem_options = config[:gem]
|
@@ -68,7 +70,7 @@ Hen :gem => :rdoc do
|
|
68
70
|
}
|
69
71
|
|
70
72
|
desc 'Display the gem specification'
|
71
|
-
task :
|
73
|
+
task :gemspec do
|
72
74
|
puts gem_spec.to_ruby
|
73
75
|
end
|
74
76
|
|
data/lib/hens/rdoc.rake
CHANGED
data/lib/hens/spec.rake
CHANGED
data/lib/hens/test.rake
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.6.
|
4
|
+
version: 0.0.6.183
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01-
|
12
|
+
date: 2008-01-21 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
requirements:
|
29
29
|
- - ">="
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.0.
|
31
|
+
version: 0.0.4
|
32
32
|
version:
|
33
33
|
description: Hoe or Echoe? No, thanks! Just a Rake helper that fits my own personal style.
|
34
34
|
email: jens.wille@uni-koeln.de
|
@@ -60,15 +60,15 @@ has_rdoc: true
|
|
60
60
|
homepage: http://prometheus.rubyforge.org/hen
|
61
61
|
post_install_message:
|
62
62
|
rdoc_options:
|
63
|
+
- --inline-source
|
64
|
+
- --charset
|
65
|
+
- UTF-8
|
63
66
|
- --title
|
64
67
|
- hen Application documentation
|
65
68
|
- --all
|
66
|
-
- --line-numbers
|
67
|
-
- --inline-source
|
68
69
|
- --main
|
69
70
|
- README
|
70
|
-
- --
|
71
|
-
- UTF-8
|
71
|
+
- --line-numbers
|
72
72
|
require_paths:
|
73
73
|
- lib
|
74
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|