-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add new show
command
#43
Changes from all commits
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 |
---|---|---|
@@ -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. |
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; | ||
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. I wasn't sure if you would prefer to use 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. I find You could further simplify the predicate to |
||
|
||
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; |
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.
Here we need to add
need_config => 1,
(see below)