Skip to content

Commit

Permalink
Serge: display version information with the --version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
julen authored and prat0088 committed Jan 2, 2017
1 parent f6f38ce commit 233351b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Revision history
- When job fails, we now move on to the next job in the config
(previously the entire config would be skipped)

- Added version information to the CLI via the `--version` flag (#38)

1.1 April 20, 2016

- On OS X, expand `~` to the actual `$HOME` path in SQLite DB connection string (#1)
Expand Down
8 changes: 7 additions & 1 deletion doc/html/serge.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1 id="NAME">NAME</h1>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<p><code>serge &lt;command&gt; [command-specific-parameters] [--command-specific-options] [--debug]</code></p>
<p><code>serge [--version] &lt;command&gt; [command-specific-parameters] [--command-specific-options] [--debug]</code></p>

<p>Run <code>serge help &lt;command&gt;</code> for help on a particular command.</p>

Expand Down Expand Up @@ -52,6 +52,12 @@ <h1 id="OPTIONS">OPTIONS</h1>

<dl>

<dt><b>--version</b></dt>
<dd>

<p>Print Serge version information and exit.</p>

</dd>
<dt><b>--dry-run</b></dt>
<dd>

Expand Down
4 changes: 4 additions & 0 deletions doc/pod/serge.pod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ replacing original strings with translated ones.

=over 8

=item B<--version>

Print Serge version information and exit.

=item B<--dry-run>

Just report and validate configuration files, but do no actual
Expand Down
16 changes: 12 additions & 4 deletions lib/Serge/Application.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use File::Find qw(find);
use File::Spec::Functions qw(rel2abs catfile);
use Getopt::Long qw(:config no_auto_abbrev no_ignore_case pass_through);
use Serge::Config::Collector;
use Serge;

sub new {
my ($class) = @_;
Expand All @@ -24,12 +25,21 @@ sub new {
sub run {
my ($self) = @_;

my ($help, $debug);
my ($help, $debug, $version);
my $result = GetOptions(
'help' => \$help,
'debug' => \$debug,
'version' => \$version,
);

my $command = shift @ARGV;

# print out version when passing the flag to a bare `serge` command
if ($version && $command eq '') {
print "Serge $Serge::VERSION\n";
exit(0);
}

if (!$result) {
$self->error("Failed to parse some command-line parameters.");
}
Expand All @@ -47,8 +57,6 @@ sub run {

$self->load_command_plugins;

my $command = shift @ARGV;

my $handler = $self->{commands}->{$command};
if (!$handler) {
$self->error("Unknown command: $command\n");
Expand Down Expand Up @@ -172,4 +180,4 @@ sub error {
exit($exitstatus);
}

1;
1;

0 comments on commit 233351b

Please sign in to comment.