Sha256: 2bd9181a707bf81f220ff3d3a9fcbc90c6008bb981ba88f2c9790ca9357ff45b
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
module Noe class Main # # List available templates # # SYNOPSIS # #{program_name} #{command_name} # # DESCRIPTION # This command lists project templates found in the templates folder. # The later is checked as a side effect. # # TIP # Run this command to know where templates are located! # class List < Quickl::Command(__FILE__, __LINE__) include Noe::Commons options do |opt| Commons.add_common_options(opt) end def max(i,j) i > j ? i : j end def execute(args) unless args.empty? raise Quickl::InvalidArgument, "Needless argument: #{args.join(', ')}" end tpls = templates_dir.glob('**').map { |tpldir| Template.new(tpldir) } columns = [:name, :version, :layouts, :summary] data = [ columns ] + tpls.collect{|tpl| begin columns.collect{|col| if col == :layouts (tpl.send(col) - ["noespec"]).to_a.join(',') else tpl.send(col).to_s.strip end } rescue Exception => ex [ tpl.name, "", "", "Template error: #{ex.message}" ] end } lengths = data.inject([0,0,0,0]){|memo,cols| (0..3).collect{|i| max(memo[i], cols[i].to_s.length)} } puts "Templates available in #{templates_dir}" data.each_with_index do |line,i| current = (config.default == line[0]) arrow = (current ? " -> " : " ") puts arrow + "%-#{lengths[0]}s %-#{lengths[1]}s %-#{lengths[2]}s %-#{lengths[3]}s" % line if i==0 puts "-"*lengths.inject(0){|memo,j| memo+j+3} end end end end # class List end # class Main end # module Noe
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
noe-1.7.6 | lib/noe/list.rb |
noe-1.7.5 | lib/noe/list.rb |
noe-1.7.4 | lib/noe/list.rb |