diff --git a/lib/puppet/face/module_tool/install.rb b/lib/puppet/face/module_tool/install.rb new file mode 100644 index 000000000..7d136d139 --- /dev/null +++ b/lib/puppet/face/module_tool/install.rb @@ -0,0 +1,75 @@ +Puppet::Face.define(:module_tool, '0.0.1') do + action(:install) do + summary "Install a module from a repository or release archive." + description <<-EOT + Install a module from a release archive file on-disk or by downloading + one from a repository. Unpack the archive into the install directory + specified by the --install-dir option, which defaults to the first + directory in the modulepath. + EOT + + returns "Pathname object representing the path to the installed module." + + examples <<-EOT + Install a module from the default repository: + + $ puppet module_tool install username-modulename + + Install a specific module version from a repository: + + $ puppet module_tool install username-modulename --version=0.0.1 + + Install a module into a specific directory: + + $ puppet module_tool install username-modulename --install-dir=path + + Install a module from a release archive: + + $ puppet module_tool install username-modulename-0.0.1.tar.gz + EOT + + arguments "" + + option "--force", "-f" do + summary "Force overwrite of existing module, if any." + description <<-EOT + Force overwrite of existing module, if any. + EOT + end + + option "--install-dir=", "-i=" do + default_to { Puppet.settings[:modulepath].split(File::PATH_SEPARATOR).first } + summary "The directory into which modules are installed." + description <<-EOT + The directory into which modules are installed, defaults to the first + directory in the modulepath. + EOT + end + + option "--module-repository=", "-r=" do + default_to { Puppet.settings[:module_repository] } + summary "Module repository to use." + description <<-EOT + Module repository to use. + EOT + end + + option "--version=", "-v=" do + summary "Module version to install." + description <<-EOT + Module version to install, can be a requirement string, eg '>= 1.0.3', + defaults to latest version. + EOT + end + + when_invoked do |name, options| + Puppet::Module::Tool::Applications::Installer.run(name, options) + end + + when_rendering :console do |return_value| + # Get the string representation of the Pathname object and print it to + # the console. + return_value.to_s + end + end +end diff --git a/spec/unit/face/module_tool/install_spec.rb b/spec/unit/face/module_tool/install_spec.rb new file mode 100644 index 000000000..3c772baf3 --- /dev/null +++ b/spec/unit/face/module_tool/install_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper' +require 'puppet/face' + +describe "puppet module_tool install" do + subject { Puppet::Face[:module_tool, :current] } + + let(:options) do + {} + end + + describe "option validation" do + let(:expected_options) do + { + :install_dir => "/dev/null/modules", + :module_repository => "http://forge.puppetlabs.com", + } + end + + context "without any options" do + it "should require a name" do + pattern = /wrong number of arguments/ + expect { subject.install }.to raise_error ArgumentError, pattern + end + + it "should not require any options" do + Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once + subject.install("puppetlabs-apache") + end + end + + it "should accept the --force option" do + options[:force] = true + expected_options.merge!(options) + Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once + subject.install("puppetlabs-apache", options) + end + + it "should accept the --install-dir option" do + options[:install_dir] = "/foo/puppet/modules" + expected_options.merge!(options) + Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once + subject.install("puppetlabs-apache", options) + end + + it "should accept the --module-repository option" do + options[:module_repository] = "http://forge.example.com" + expected_options.merge!(options) + Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once + subject.install("puppetlabs-apache", options) + end + + it "should accept the --version option" do + options[:version] = "0.0.1" + expected_options.merge!(options) + Puppet::Module::Tool::Applications::Installer.expects(:run).with("puppetlabs-apache", expected_options).once + subject.install("puppetlabs-apache", options) + end + end + + describe "inline documentation" do + subject { Puppet::Face[:module_tool, :current].get_action :install } + + its(:summary) { should =~ /install.*module/im } + its(:description) { should =~ /install.*module/im } + its(:returns) { should =~ /pathname/i } + its(:examples) { should_not be_empty } + + %w{ license copyright summary description returns examples }.each do |doc| + context "of the" do + its(doc.to_sym) { should_not =~ /(FIXME|REVISIT|TODO)/ } + end + end + end +end