cmd/manifest.rb in bahuvrihi-tap-0.10.7 vs cmd/manifest.rb in bahuvrihi-tap-0.10.8
- old
+ new
@@ -1,94 +1,102 @@
# tap manifest
#
-# Prints information about each env.
+# Prints information about the current tap environment.
#
options = {}
OptionParser.new do |opts|
opts.separator ""
opts.separator "options:"
opts.on("-h", "--help", "Show this message") do
- opts.banner = cmdline.usage(__FILE__)
+ opts.banner = Tap::Support::Lazydoc.usage(__FILE__)
puts opts
exit
end
- opts.on("-e", "--envs_only", "Only list environments") do
- options[:envs_only] = true
- end
+ # opts.on("-t", "--tree", "Just print the env tree.") do
+ # options[:tree] = true
+ # end
- opts.on("-r", "--require FILEPATH", "Require the specified file") do |value|
- require value
- end
+ # opts.on("-r", "--require FILEPATH", "Require the specified file") do |value|
+ # require value
+ # end
end.parse!(ARGV)
-# Simply a method to collect and format paths for
-# the specified manifest.
-def collect_map(env, manifest)
- width = 10
- map = manifest.minimize.collect do |(key, path)|
- path = case path
- when Tap::Support::Constant then path.require_path
- else path
- end
-
- width = key.length if width < key.length
- [key, env.root.relative_filepath(:root, path) || path]
- end.collect do |args|
- "%-#{width}s (%s)" % args
- end
-
- map.unshift("") unless map.empty?
- map
+env = Tap::Env.instance
+env_names = {}
+env.manifest(:envs, true).minimize.each do |name, environment|
+ env_names[environment] = name
end
-# Collect remaining args as
-env = Tap::Env.instance
-envs_manifest = if ARGV.empty?
- env.manifest(:envs, true).minimize
+filter = case
+when ARGV.empty? then env_names.keys
else
ARGV.collect do |name|
- entry = env.find(:envs, name, false)
- raise "could not find an env matching: #{name}" if entry == nil
- entry
+ unless entry = env.find(:envs, name, false)
+ raise "could not find an env matching: #{name}"
+ end
+
+ entry[1]
end
end
-width = 10
-envs_manifest.each {|(env_name, e)| width = env_name.length if width < env_name.length}
-width += 2
+template = %Q{#{'-' * 80}
+<%= (env_name + ':').ljust(width) %> (<%= env.root.root %>)
+<% manifests.each do |manifest_name, entries| %>
+ <%= manifest_name %>
+<% entries.each do |name, path| %>
+ <%= name.ljust(width-4) %> (<%= path %>)
+<% end %>
+<% end %>
+}
-env.each do |current|
- env_name, current = envs_manifest.find {|(env_name, e)| e == current }
- next if env_name == nil
+width = 10
+summary = env.inspect(template) do |templater, share|
+ current = templater.env
+ next unless filter.include?(current)
- puts '-' * 80 unless options[:envs_only]
- puts "%-#{width}s (%s)" % [env_name + ':', current.root.root]
-
- next if options[:envs_only]
-
manifest_keys = (Tap::Env.manifests.keys + current.manifests.keys).uniq
- manifest_keys.each do |name|
+ manifests = manifest_keys.collect do |name|
next if name == :envs
+
manifest = current.manifest(name, true)
next if manifest.empty?
- puts " %-10s %s" % [name, collect_map(current, manifest).join("\n ")]
+ entries = manifest.minimize.collect do |(entry, path)|
+ path = case path
+ when Tap::Support::Constant then path.require_path
+ else path
+ end
+
+ width = entry.length if width < entry.length
+ [entry, current.root.relative_filepath(:root, path) || path]
+ end
+
+ [name, entries]
end
+ templater.manifests = manifests.compact
+ templater.env_name = env_names[current]
+
+ width = templater.env_name.length if width < templater.env_name.length
+ share[:width] = width + 2
end
+puts summary
if ARGV.empty?
- puts '-' * 80
- puts
- env.recursive_each(0, nil) do |current, nesting_depth, last_env|
- env_name, current = envs_manifest.find {|(env_name, e)| e == current }
-
- leader = nesting_depth == 0 ? "" : '| ' * (nesting_depth - 1) + (last_env == current ? "`- " : "|- ")
- puts("#{leader}#{env_name}")
+ tree = env.recursive_inspect("<%= leader %><%= env_name %> \n", 0, nil) do |templater, share, nesting_depth, last|
+ current = templater.env
+
+ templater.leader = nesting_depth == 0 ? "" : '| ' * (nesting_depth - 1) + (last == current ? "`- " : "|- ")
+ templater.env_name = env_names[current]
+
[nesting_depth + 1, current.envs[-1]]
end
+
+ puts '-' * 80
+ puts
+ puts tree
puts
end
\ No newline at end of file