-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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' | ||
}, | ||
} | ||
} | ||
|
||
sub run { | ||
my $config_file = $ARGV[0]; | ||
|
||
die "No configuration file specified\n" unless defined $config_file; | ||
die "Multiple configuration files not allowed\n" unless $#ARGV == 0; | ||
|
||
my $cfg = Config::Neat::Inheritable->new(); | ||
my $data = $cfg->parse_file($config_file); | ||
|
||
my $renderer = Config::Neat::Render->new(); | ||
print $renderer->render($data); | ||
|
||
return 0; | ||
} | ||
|
||
1; |