Skip to content

Commit

Permalink
Add new show command (#43)
Browse files Browse the repository at this point in the history
This command expands the configuration file's @inherit
rules and prints the final configuration nicely formatted,
similar to what `dump-nconf <config-file>` does.
  • Loading branch information
julen authored and Igor Afanasyev committed Jul 25, 2019
1 parent 8853c60 commit 1a2871d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Revision history
(in addition to extracting them as translation hints).

- Added support for `use_keys_as_context` job parameter (#89).

- Added new `show` command to display expanded .serge configurations (#40).

- Miscellaneous smaller fixes and improvements.

Expand Down
19 changes: 19 additions & 0 deletions doc/pod/serge-show.pod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=head1 NAME

serge-show - Show expanded version of a configuration file

=head1 SYNOPSIS

C<< serge show <configuration-file> >>

Where C<< <configuration-file> >> is a path to a specific .serge file.

=head1 DESCRIPTION

B<serge-show> 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<serge> suite.
34 changes: 34 additions & 0 deletions lib/Serge/Command/show.pm
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 1a2871d

Please sign in to comment.