From 191872b23ff676954b4febb14c17ef3c9772917f Mon Sep 17 00:00:00 2001 From: Julen Ruiz Aizpuru Date: Wed, 26 Oct 2016 14:02:27 +0200 Subject: [PATCH] Add new `show` command When configurations use inheritance, it is handy to see the expanded configuration to get a better feel of what is going to be run. While Config::Neat already provides a command for this, having a `show` command helps with the feature being discoverable. --- CHANGES | 4 ++++ doc/pod/serge-show.pod | 19 +++++++++++++++++++ lib/Serge/Command/show.pm | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 doc/pod/serge-show.pod create mode 100644 lib/Serge/Command/show.pm diff --git a/CHANGES b/CHANGES index 68703bda..1ad454a8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Revision history +v.next (Not release yet) + + - Added new `show` command to display expanded .serge configurations (#40). + 1.2 October 29, 2016 - Make TS File serialization pluggable (see #11) diff --git a/doc/pod/serge-show.pod b/doc/pod/serge-show.pod new file mode 100644 index 00000000..1ec64248 --- /dev/null +++ b/doc/pod/serge-show.pod @@ -0,0 +1,19 @@ +=head1 NAME + +serge-show - Show expanded version of a configuration file + +=head1 SYNOPSIS + +C<< serge show >> + +Where C<< >> is a path to a specific .serge file. + +=head1 DESCRIPTION + +B prints out the interpreted configuration file by applying all +inheritance rules. This is useful to check the full configuration that will be +used by Serge. + +=head1 SEE ALSO + +Part of L suite. diff --git a/lib/Serge/Command/show.pm b/lib/Serge/Command/show.pm new file mode 100644 index 00000000..36138dc2 --- /dev/null +++ b/lib/Serge/Command/show.pm @@ -0,0 +1,34 @@ +package Serge::Command::show; +use parent Serge::Command; + +use strict; + +use Config::Neat::Inheritable; +use Config::Neat::Render; + +sub get_commands { + return { + show => { + handler => \&run, + info => 'Show expanded version of a configuration file', + need_config => 1, + }, + } +} + +sub run { + my ($self) = @_; + + my @config_files = $self->{parent}->get_config_files; + die "Multiple configuration files not allowed\n" unless $#config_files == 0; + + my $cfg = Config::Neat::Inheritable->new(); + my $data = $cfg->parse_file($config_files[0]); + + my $renderer = Config::Neat::Render->new(); + print $renderer->render($data); + + return 0; +} + +1;