hen 0.0.5.164 → 0.0.6.166
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +7 -1
- data/README +1 -1
- data/bin/hen +56 -9
- data/lib/hen.rb +41 -22
- data/lib/hen/cli.rb +37 -5
- data/lib/hen/version.rb +1 -1
- metadata +4 -4
- data/example/Rakefile +0 -24
data/ChangeLog
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Revision history for hen
|
2
2
|
|
3
|
+
== 0.0.6 [2008-01-09]
|
4
|
+
|
5
|
+
* Added basic sample project tree (skeleton for 'hen create')
|
6
|
+
* Lazily find and load .henrc
|
7
|
+
* Some polishing and fixes
|
8
|
+
|
3
9
|
== 0.0.5 [2008-01-08]
|
4
10
|
|
5
11
|
* Replaced 'hen' executable stub with something actually useful
|
@@ -12,7 +18,7 @@
|
|
12
18
|
|
13
19
|
== 0.0.3 [2008-01-04]
|
14
20
|
|
15
|
-
* More cleanup and maturing
|
21
|
+
* More cleanup and maturing
|
16
22
|
* New tasks 'release' (formerly 'upload_gem'), 'publish_docs', and 'debug_gem'
|
17
23
|
* All in all: Pretty much inspired by Hoe ;-)
|
18
24
|
|
data/README
CHANGED
data/bin/hen
CHANGED
@@ -50,6 +50,8 @@ EOT
|
|
50
50
|
|
51
51
|
abort USAGE if ARGV.empty?
|
52
52
|
|
53
|
+
EXAMPLE = File.join(File.dirname(__FILE__), '..', 'example')
|
54
|
+
|
53
55
|
case action = ARGV.shift
|
54
56
|
when '-h', '--help'
|
55
57
|
puts USAGE
|
@@ -62,28 +64,73 @@ case action = ARGV.shift
|
|
62
64
|
puts " %-#{m}s - %s" % [a, d]
|
63
65
|
}
|
64
66
|
when 'config'
|
65
|
-
henrc = File.join(
|
67
|
+
henrc = File.join(EXAMPLE, '.henrc')
|
66
68
|
|
67
69
|
# TODO: DRY up with lib/hen.rb
|
68
70
|
target = File.join(ENV['HOME'] || File.expand_path('~'), '.henrc')
|
69
71
|
|
70
72
|
render(henrc, target)
|
71
73
|
|
74
|
+
puts
|
72
75
|
puts "Your .henrc has been created: #{target}. Modify to your needs."
|
73
76
|
when 'create'
|
74
|
-
path = ARGV.shift
|
77
|
+
path = File.expand_path(ARGV.shift)
|
75
78
|
abort 'Path argument missing!' unless path
|
76
79
|
|
77
|
-
|
80
|
+
template = File.join(EXAMPLE, 'project')
|
81
|
+
abort "Sample project tree not found: #{template}" unless File.directory?(template)
|
82
|
+
|
83
|
+
if File.directory?(path)
|
84
|
+
abort "Target directory already exists: #{path}. Won't touch."
|
85
|
+
else
|
86
|
+
Dir.mkdir(path)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Parts to be replaced by the user
|
90
|
+
replacements = {}
|
91
|
+
|
92
|
+
begin
|
93
|
+
# Keep track of what's been created
|
94
|
+
created = [path]
|
95
|
+
|
96
|
+
progname = ask!("Program's name")
|
97
|
+
|
98
|
+
Dir.chdir(template) {
|
99
|
+
Dir['**/*'].each { |sample|
|
100
|
+
target = File.join(path, sample.gsub(/__progname__/, progname))
|
101
|
+
created << target
|
102
|
+
|
103
|
+
if File.directory?(sample)
|
104
|
+
Dir.mkdir(target)
|
105
|
+
else
|
106
|
+
content = render(sample, target)
|
107
|
+
replacements[target] = content.scan(/### .* ###/)
|
108
|
+
end
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
# If we got here, everything went fine...
|
113
|
+
created.clear
|
114
|
+
ensure
|
115
|
+
# In case of an exception or premature program exit: Clean up!
|
116
|
+
created.reverse.each { |target|
|
117
|
+
(File.directory?(target) ? Dir : File).unlink(target)
|
118
|
+
}
|
119
|
+
end
|
78
120
|
|
79
|
-
|
80
|
-
|
121
|
+
puts
|
122
|
+
puts "Your new project directory has been created: #{path}"
|
81
123
|
|
82
|
-
|
83
|
-
|
124
|
+
replacements.each { |target, parts|
|
125
|
+
next if parts.empty?
|
84
126
|
|
85
|
-
|
86
|
-
|
127
|
+
puts
|
128
|
+
puts "#{target}:"
|
129
|
+
|
130
|
+
parts.each { |part|
|
131
|
+
puts " #{part}"
|
132
|
+
}
|
133
|
+
}
|
87
134
|
when 'list'
|
88
135
|
abort 'Sorry, not yet available...'
|
89
136
|
else
|
data/lib/hen.rb
CHANGED
@@ -45,36 +45,15 @@ class Hen
|
|
45
45
|
# Directories to search for .henrc
|
46
46
|
RCDIRS = ['.', ENV['HOME'], File.expand_path('~')]
|
47
47
|
|
48
|
-
find_henrc = if henrc = ENV['HENRC']
|
49
|
-
if File.readable?(henrc)
|
50
|
-
henrc
|
51
|
-
else
|
52
|
-
abort "The specified .henrc file could not be found: #{henrc}"
|
53
|
-
end
|
54
|
-
else
|
55
|
-
RCDIRS.find { |path|
|
56
|
-
henrc = File.join(path, '.henrc')
|
57
|
-
break henrc if File.readable?(henrc)
|
58
|
-
} or abort %q{
|
59
|
-
No .henrc file could be found! Please create one first with 'hen config'.
|
60
|
-
}
|
61
|
-
end
|
62
|
-
|
63
|
-
# The path to the user's .henrc
|
64
|
-
HENRC = find_henrc
|
65
|
-
|
66
48
|
# A container for all loaded hens
|
67
49
|
@hens = {}
|
68
50
|
|
69
|
-
# The configuration resulting from the user's .henrc
|
70
|
-
@config = YAML.load_file(HENRC)
|
71
|
-
|
72
51
|
# The verbosity concerning errors and warnings
|
73
52
|
@verbose = true
|
74
53
|
|
75
54
|
class << self
|
76
55
|
|
77
|
-
attr_reader :hens, :
|
56
|
+
attr_reader :hens, :verbose
|
78
57
|
|
79
58
|
# call-seq:
|
80
59
|
# lay!
|
@@ -141,6 +120,46 @@ class Hen
|
|
141
120
|
@hens[hen]
|
142
121
|
end
|
143
122
|
|
123
|
+
# call-seq:
|
124
|
+
# henrc => aString
|
125
|
+
#
|
126
|
+
# The path to the user's .henrc
|
127
|
+
def henrc
|
128
|
+
@henrc ||= if henrc = ENV['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
|
140
|
+
end
|
141
|
+
|
142
|
+
# call-seq:
|
143
|
+
# config => aHash
|
144
|
+
# config(key) => aValue
|
145
|
+
#
|
146
|
+
# The configuration resulting from the user's .henrc. Takes optional
|
147
|
+
# +key+ argument as "path" into the config hash, returning the thusly
|
148
|
+
# retrieved value.
|
149
|
+
#
|
150
|
+
# Example:
|
151
|
+
# config('a/b/c') #=> @config[:a][:b][:c]
|
152
|
+
def config(key = default = Object.new)
|
153
|
+
@config ||= YAML.load_file(henrc)
|
154
|
+
|
155
|
+
return @config if key == default
|
156
|
+
|
157
|
+
key.split('/').inject(@config) { |value, k|
|
158
|
+
value.fetch(k.to_sym)
|
159
|
+
}
|
160
|
+
rescue IndexError, NoMethodError
|
161
|
+
end
|
162
|
+
|
144
163
|
private
|
145
164
|
|
146
165
|
# call-seq:
|
data/lib/hen/cli.rb
CHANGED
@@ -33,21 +33,53 @@ require 'highline/import'
|
|
33
33
|
|
34
34
|
module Hen::CLI
|
35
35
|
|
36
|
+
# Collect user's answers by key, so we don't have to ask again.
|
37
|
+
@@values = {}
|
38
|
+
|
36
39
|
alias_method :original_ask, :ask
|
37
|
-
|
38
|
-
|
40
|
+
|
41
|
+
# Ask the user to enter an appropriate value for +key+. Uses
|
42
|
+
# already stored answer if present, unless +cached+ is false.
|
43
|
+
def ask(key, config_key = false, cached = true)
|
44
|
+
@@values[key] = nil unless cached
|
45
|
+
|
46
|
+
@@values[key] ||=
|
47
|
+
Hen.config(config_key) || original_ask("Please enter your #{key}: ")
|
48
|
+
rescue Interrupt
|
49
|
+
abort ''
|
39
50
|
end
|
40
51
|
|
41
|
-
|
42
|
-
|
52
|
+
# Same as ask, but requires a non-empty value to be entered.
|
53
|
+
def ask!(key, config_key = false)
|
54
|
+
msg = "#{key} is required! Please enter a non-empty value."
|
55
|
+
max = 3
|
56
|
+
|
57
|
+
(0...max).each { |i|
|
58
|
+
value = ask(key, config_key, i.zero?)
|
59
|
+
return value unless value.empty?
|
60
|
+
|
61
|
+
puts msg
|
62
|
+
}
|
63
|
+
|
64
|
+
abort "You had #{max} tries -- now be gone!"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Renders the contents of +sample+ as an ERb template,
|
68
|
+
# storing the result in +target+. Returns the content.
|
69
|
+
def render(sample, target)
|
70
|
+
abort "Sample file not found: #{sample}" unless File.readable?(sample)
|
43
71
|
|
44
72
|
if File.readable?(target)
|
45
73
|
abort unless agree("Target file already exists: #{target}. Overwrite? ")
|
46
74
|
end
|
47
75
|
|
76
|
+
content = ERB.new(File.read(sample)).result(binding)
|
77
|
+
|
48
78
|
File.open(target, 'w') { |f|
|
49
|
-
f.puts
|
79
|
+
f.puts content unless content.empty?
|
50
80
|
}
|
81
|
+
|
82
|
+
content
|
51
83
|
end
|
52
84
|
|
53
85
|
end
|
data/lib/hen/version.rb
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.
|
4
|
+
version: 0.0.6.166
|
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-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,7 @@ files:
|
|
54
54
|
- lib/hens/gem.rake
|
55
55
|
- lib/hens/test.rake
|
56
56
|
- lib/hens/rdoc.rake
|
57
|
-
- example/
|
57
|
+
- example/project
|
58
58
|
- example/.henrc
|
59
59
|
has_rdoc: true
|
60
60
|
homepage: http://prometheus.rubyforge.org/hen
|
@@ -64,9 +64,9 @@ rdoc_options:
|
|
64
64
|
- hen Application documentation
|
65
65
|
- --all
|
66
66
|
- --line-numbers
|
67
|
+
- --inline-source
|
67
68
|
- --main
|
68
69
|
- README
|
69
|
-
- --inline-source
|
70
70
|
- --charset
|
71
71
|
- UTF-8
|
72
72
|
require_paths:
|
data/example/Rakefile
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'hen'
|
3
|
-
rescue LoadError
|
4
|
-
abort "Please install the 'hen' gem first."
|
5
|
-
end
|
6
|
-
|
7
|
-
PROGNAME = %q{<%= ask 'Program name' %>}
|
8
|
-
|
9
|
-
require File.join('lib', PROGNAME, 'version')
|
10
|
-
|
11
|
-
Hen.lay! {{
|
12
|
-
:rubyforge => {
|
13
|
-
:project => %q{<%= ask 'Rubyforge project name' %>},
|
14
|
-
:package => PROGNAME
|
15
|
-
},
|
16
|
-
|
17
|
-
:gem => {
|
18
|
-
:version => <%= ask 'Module/Class name' %>::VERSION,
|
19
|
-
:summary => %q{<%= ask 'Program description summary' %>},
|
20
|
-
:files => FileList['lib/**/*.rb'].to_a,
|
21
|
-
:extra_files => FileList['[A-Z]*'].to_a,
|
22
|
-
:dependencies => %w[]
|
23
|
-
}
|
24
|
-
}}
|