New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PUP-8482) Add Puppet Extended S-Expression Notation #6673
Changes from 5 commits
cb616d9
7aa5ae7
f512c8d
c0de913
d165f39
0608a76
fb9f8e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,13 +104,19 @@ | |
|
||
action (:dump) do | ||
summary _("Outputs a dump of the internal template parse tree for debugging") | ||
arguments "-e <source> | [<templates> ...] " | ||
arguments "[--format <old|pn|json>] [--pretty] { -e <source> | [<templates> ...] } " | ||
returns _("A dump of the resulting AST model unless there are syntax or validation errors.") | ||
description <<-'EOT' | ||
The dump action parses and validates the EPP syntax and dumps the resulting AST model | ||
in a human readable (but not necessarily an easy to understand) format. | ||
The output format of the dumped tree is intended for epp parser debugging purposes | ||
and is not API, and may thus change between versions without deprecation warnings. | ||
|
||
The output format can be controlled using the --format <old|pn|json> | ||
'old' is the default, but now deprecated format which is not API. | ||
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. | ||
|
||
The output will be "pretty printed" when the option --pretty is given together with --format 'pn' or'json'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing space between |
||
This option has no effect on the 'old' format. | ||
|
||
The command accepts one or more templates (.epp) files, or an -e followed by the template | ||
source text. The given templates can be paths to template files, or references | ||
|
@@ -137,6 +143,14 @@ | |
summary _("Whether or not to validate the parsed result, if no-validate only syntax errors are reported.") | ||
end | ||
|
||
option('--format ' + _('<old, pn, or json>')) do | ||
summary _("Get result in 'old' (deprecated format), 'pn' (new format), or 'json' (new format in JSON).") | ||
end | ||
|
||
option('--pretty') do | ||
summary _('Pretty print output. Only applicable together with --format pn or json') | ||
end | ||
|
||
option("--[no-]header") do | ||
summary _("Whether or not to show a file name header between files.") | ||
end | ||
|
@@ -353,7 +367,6 @@ | |
|
||
def dump_parse(source, filename, options, show_filename = true) | ||
output = "" | ||
dumper = Puppet::Pops::Model::ModelTreeDumper.new | ||
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new | ||
begin | ||
if options[:validate] | ||
|
@@ -365,7 +378,19 @@ def dump_parse(source, filename, options, show_filename = true) | |
if show_filename && options[:header] | ||
output << "--- #{filename}\n" | ||
end | ||
output << dumper.dump(parse_result) << "\n" | ||
fmt = options[:format] | ||
if fmt.nil? || fmt == 'old' | ||
output << Puppet::Pops::Model::ModelTreeDumper.new.dump(parse_result) << "\n" | ||
else | ||
require 'puppet/pops/pn' | ||
pn = Puppet::Pops::Model::PNTransformer.transform(parse_result) | ||
case fmt | ||
when 'json' | ||
options[:pretty] ? JSON.pretty_unparse(pn.to_data) : JSON.dump(pn.to_data) | ||
else | ||
pn.format(options[:pretty] ? Puppet::Pops::PN::Indent.new(' ') : nil, output) | ||
end | ||
end | ||
rescue Puppet::ParseError => detail | ||
if show_filename | ||
Puppet.err("--- #{filename}") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,12 +64,20 @@ | |
|
||
action (:dump) do | ||
summary _("Outputs a dump of the internal parse tree for debugging") | ||
arguments "-e " + _("<source>| [<manifest> ...] ") | ||
arguments "[--format <old|pn|json>] [--pretty] { -e <source> | [<templates> ...] } " | ||
returns _("A dump of the resulting AST model unless there are syntax or validation errors.") | ||
description <<-'EOT' | ||
This action parses and validates the Puppet DSL syntax without compiling a catalog | ||
or syncing any resources. | ||
|
||
The output format can be controlled using the --format <old|pn|json> | ||
'old' is the default, but now deprecated format which is not API. | ||
'pn' is the Puppet Extended S-Expression Notation. | ||
'json' outputs the same graph as 'pn' but with JSON syntax. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as earlier comment for the explanations... |
||
|
||
The output will be "pretty printed" when the option --pretty is given together with --format 'pn' or'json'. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as earlier comment for |
||
This option has no effect on the 'old' format. | ||
|
||
The command accepts one or more manifests (.pp) files, or an -e followed by the puppet | ||
source text. | ||
If no arguments are given, the stdin is read (unless it is attached to a terminal) | ||
|
@@ -87,6 +95,14 @@ | |
summary _("Whether or not to validate the parsed result, if no-validate only syntax errors are reported") | ||
end | ||
|
||
option('--format ' + _('<old, pn, or json>')) do | ||
summary _("Get result in 'old' (deprecated format), 'pn' (new format), or 'json' (new format in JSON).") | ||
end | ||
|
||
option('--pretty') do | ||
summary _('Pretty print output. Only applicable together with --format pn or json') | ||
end | ||
|
||
when_invoked do |*args| | ||
require 'puppet/pops' | ||
options = args.pop | ||
|
@@ -120,7 +136,6 @@ | |
|
||
def dump_parse(source, filename, options, show_filename = true) | ||
output = "" | ||
dumper = Puppet::Pops::Model::ModelTreeDumper.new | ||
evaluating_parser = Puppet::Pops::Parser::EvaluatingParser.new | ||
begin | ||
if options[:validate] | ||
|
@@ -132,7 +147,19 @@ def dump_parse(source, filename, options, show_filename = true) | |
if show_filename | ||
output << "--- #{filename}" | ||
end | ||
output << dumper.dump(parse_result) << "\n" | ||
fmt = options[:format] | ||
if fmt.nil? || fmt == 'old' | ||
output << Puppet::Pops::Model::ModelTreeDumper.new.dump(parse_result) << "\n" | ||
else | ||
require 'puppet/pops/pn' | ||
pn = Puppet::Pops::Model::PNTransformer.transform(parse_result) | ||
case fmt | ||
when 'json' | ||
options[:pretty] ? JSON.pretty_unparse(pn.to_data) : JSON.dump(pn.to_data) | ||
else | ||
pn.format(options[:pretty] ? Puppet::Pops::PN::Indent.new(' ') : nil, output) | ||
end | ||
end | ||
rescue Puppet::ParseError => detail | ||
if show_filename | ||
Puppet.err("--- #{filename}") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe line 113 should end with
where:
and each of the three formats starts with a*
bullet ?