diff --git a/acceptance/tests/ticket_11727_support_stdin_parsing_in_puppet_parser_validate.rb b/acceptance/tests/ticket_11727_support_stdin_parsing_in_puppet_parser_validate.rb new file mode 100644 index 000000000..707f783da --- /dev/null +++ b/acceptance/tests/ticket_11727_support_stdin_parsing_in_puppet_parser_validate.rb @@ -0,0 +1,18 @@ +test_name "#11727: support stdin parsing in puppet parser validate" + +pp = "#{scratch}/11727.pp" + +step "validate with a tty parses the default manifest" +on agents, puppet(%w{parser validate}) do + assert_match(/Validating the default manifest/, stdout, + "no message about validating default manifest") +end + +step "create the remote manifest file for redirection" +create_remote_file agents, pp 'notice("hello")' + +step "validate with redirection parses STDIN" +on agents, puppet(%w{parser validate <}, pp), do + assert_no_match(/Validating the default manifest/, stdout, + "there was message about validating default manifest despite redirect") +end diff --git a/lib/puppet/face/parser.rb b/lib/puppet/face/parser.rb index c99cbb747..3242faca7 100644 --- a/lib/puppet/face/parser.rb +++ b/lib/puppet/face/parser.rb @@ -1,42 +1,51 @@ require 'puppet/face' require 'puppet/parser' Puppet::Face.define(:parser, '0.0.1') do copyright "Puppet Labs", 2011 license "Apache 2 license; see COPYING" summary "Interact directly with the parser." action :validate do summary "Validate the syntax of one or more Puppet manifests." arguments "[] [ ...]" returns "Nothing, or the first syntax error encountered." description <<-'EOT' This action validates Puppet DSL syntax without compiling a catalog or syncing any resources. If no manifest files are provided, it will validate the default site manifest. EOT examples <<-'EOT' Validate the default site manifest at /etc/puppet/manifests/site.pp: $ puppet parser validate Validate two arbitrary manifest files: $ puppet parser validate init.pp vhost.pp + + Validate from STDIN: + + $ cat init.pp | puppet parser validate EOT when_invoked do |*args| args.pop files = args if files.empty? - files << Puppet[:manifest] - Puppet.notice "No manifest specified. Validating the default manifest #{Puppet[:manifest]}" + if not STDIN.tty? + Puppet[:code] = STDIN.read + Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types.clear + else + files << Puppet[:manifest] + Puppet.notice "No manifest specified. Validating the default manifest #{Puppet[:manifest]}" + end end files.each do |file| Puppet[:manifest] = file Puppet::Node::Environment.new(Puppet[:environment]).known_resource_types.clear end nil end end end