class Niman::CLI::Application

Attributes

client_shell[RW]
silent[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/niman/cli/application.rb, line 15
def initialize(*args)
  super
  @client_shell= Niman::Shell.new
  @silent = false
end

Public Instance Methods

apply(file='Nimanfile') click to toggle source
# File lib/niman/cli/application.rb, line 22
def apply(file='Nimanfile')
  begin
    Niman::Recipe.from_file(file)
    config = Niman::Recipe.configuration
    installer = Niman::Installer.new(shell: client_shell, managers:{
      debian: 'apt-get -y',
      redhat: 'yum -y'
    })

    resolver    = Niman::PackageResolver.new(config.instructions)
    filehandler = Niman::FileHandler.new(client_shell)
    provisioner = Niman::Provisioner.new(installer, filehandler, @client_shell, resolver.resolve)
    this = self
    provisioner.run do |instruction|
      this.say "Executing task #{instruction.description}" unless @silent
    end
  rescue LoadError => e
    client_shell.print(e.message, :error)
  rescue Niman::ConfigError => cfg_error
    client_shell.print(cfg_error.message, :error)
  end
end
setup(filename=Niman::Recipe::DEFAULT_FILENAME) click to toggle source
# File lib/niman/cli/application.rb, line 46
      def setup(filename=Niman::Recipe::DEFAULT_FILENAME)
        content = <<-EOS
# -*- mode: ruby -*-
# vi: set ft=ruby :
Niman::Recipe.configure do |config|
end
        EOS
        File.open(filename, "w") { |handle| handle.write(content) }
        say "Created new file #{filename}"
      end