Class: Niman::CLI::Application
- Inherits:
-
Thor
- Object
- Thor
- Niman::CLI::Application
- Defined in:
- lib/niman/cli/application.rb
Instance Attribute Summary collapse
-
#client_shell ⇒ Object
Returns the value of attribute client_shell.
-
#silent ⇒ Object
Returns the value of attribute silent.
Instance Method Summary collapse
- #apply(file = 'Nimanfile') ⇒ Object
-
#initialize(*args) ⇒ Application
constructor
A new instance of Application.
- #setup(filename = Niman::Recipe::DEFAULT_FILENAME) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Application
Returns a new instance of Application.
15 16 17 18 19 |
# File 'lib/niman/cli/application.rb', line 15 def initialize(*args) super @client_shell= Niman::Shell.new @silent = false end |
Instance Attribute Details
#client_shell ⇒ Object
Returns the value of attribute client_shell.
13 14 15 |
# File 'lib/niman/cli/application.rb', line 13 def client_shell @client_shell end |
#silent ⇒ Object
Returns the value of attribute silent.
13 14 15 |
# File 'lib/niman/cli/application.rb', line 13 def silent @silent end |
Instance Method Details
#apply(file = 'Nimanfile') ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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., :error) rescue Niman::ConfigError => cfg_error client_shell.print(cfg_error., :error) end end |
#setup(filename = Niman::Recipe::DEFAULT_FILENAME) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# 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 |