Class: Pakman::Gen

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging, ManifestHelper
Defined in:
lib/pakman/cli/commands/gen.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ManifestHelper

#installed_template_manifest_patterns, #installed_template_manifests

Constructor Details

#initialize(opts) ⇒ Gen

Returns a new instance of Gen.



9
10
11
# File 'lib/pakman/cli/commands/gen.rb', line 9

def initialize( opts )
  @opts    = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



13
14
15
# File 'lib/pakman/cli/commands/gen.rb', line 13

def opts
  @opts
end

Instance Method Details

#run(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pakman/cli/commands/gen.rb', line 15

def run( args )
  manifest_name = opts.manifest
  manifest_name = manifest_name.downcase.gsub('.txt', '' )  # remove .txt if present
  
  logger.debug "manifest=#{manifest_name}"

  # check for matching manifests
  manifests = installed_template_manifests.select { |m| m[0] == manifest_name+'.txt' }
      
  if manifests.empty?
    puts "*** error: unknown template pack '#{manifest_name}'; use pakman -l to list installed template packs"
    exit 2
  end
      
  manifestsrc = manifests[0][1]
  pakpath     = opts.output_path
  
  if args.empty?
    Copier.new.copy_pak( manifestsrc, pakpath )
  else
    args.each do |arg|
      data = YAML.load_file( arg )
      name = File.basename( arg, '.*' )
      puts "#{name}:"
      pp data
      Templater.new.merge_pak( manifestsrc, pakpath, Ctx.new(data).ctx, name )
    end
  end
  
end