# File lib/puppet/application/apply.rb, line 76
 76:   def main
 77:     # Set our code or file to use.
 78:     if options[:code] or command_line.args.length == 0
 79:       Puppet[:code] = options[:code] || STDIN.read
 80:     else
 81:       manifest = command_line.args.shift
 82:       raise "Could not find file #{manifest}" unless File.exist?(manifest)
 83:       Puppet.warning("Only one file can be applied per run.  Skipping #{command_line.args.join(', ')}") if command_line.args.size > 0
 84:       Puppet[:manifest] = manifest
 85:     end
 86: 
 87:     # Collect our facts.
 88:     unless facts = Puppet::Node::Facts.find(Puppet[:certname])
 89:       raise "Could not find facts for #{Puppet[:certname]}"
 90:     end
 91: 
 92:     # Find our Node
 93:     unless node = Puppet::Node.find(Puppet[:certname])
 94:       raise "Could not find node #{Puppet[:certname]}"
 95:     end
 96: 
 97:     # Merge in the facts.
 98:     node.merge(facts.values)
 99: 
100:     # Allow users to load the classes that puppet agent creates.
101:     if options[:loadclasses]
102:       file = Puppet[:classfile]
103:       if FileTest.exists?(file)
104:         unless FileTest.readable?(file)
105:           $stderr.puts "#{file} is not readable"
106:           exit(63)
107:         end
108:         node.classes = File.read(file).split(/[\s\n]+/)
109:       end
110:     end
111: 
112:     begin
113:       # Compile our catalog
114:       starttime = Time.now
115:       catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node)
116: 
117:       # Translate it to a RAL catalog
118:       catalog = catalog.to_ral
119: 
120:       catalog.finalize
121: 
122:       catalog.retrieval_duration = Time.now - starttime
123: 
124:       require 'puppet/configurer'
125:       configurer = Puppet::Configurer.new
126:       report = configurer.run(:skip_plugin_download => true, :catalog => catalog)
127: 
128:       exit( Puppet[:noop] ? 0 : options[:detailed_exitcodes] ? report.exit_status : 0 )
129:     rescue => detail
130:       puts detail.backtrace if Puppet[:trace]
131:       $stderr.puts detail.message
132:       exit(1)
133:     end
134:   end