Skip to content
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

Merged
merged 2 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

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)

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if you would prefer to use $#config_files == 0 or rather scalar @config_files == 1. Please let me know if you have any preferences.

Copy link
Contributor

@prat0088 prat0088 Dec 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find scalar(@config_files) == 1 easier to read. $# is less common, requires extra Perl knowledge, and it looks like a check for a zero-length list if you're just skimming code.

You could further simplify the predicate to @config_files == 1.


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;