diff --git a/CHANGES b/CHANGES index e468a9a0..614b5f5f 100644 --- a/CHANGES +++ b/CHANGES @@ -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) diff --git a/doc/html/serge.html b/doc/html/serge.html index 44990ca6..c0af4ae7 100644 --- a/doc/html/serge.html +++ b/doc/html/serge.html @@ -24,7 +24,7 @@

NAME

SYNOPSIS

-

serge <command> [command-specific-parameters] [--command-specific-options] [--debug]

+

serge [--version] <command> [command-specific-parameters] [--command-specific-options] [--debug]

Run serge help <command> for help on a particular command.

@@ -52,6 +52,12 @@

OPTIONS

+
--version
+
+ +

Print Serge version information and exit.

+ +
--dry-run
diff --git a/doc/pod/serge.pod b/doc/pod/serge.pod index 2f0e5e28..e59b91b3 100644 --- a/doc/pod/serge.pod +++ b/doc/pod/serge.pod @@ -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 diff --git a/lib/Serge/Application.pm b/lib/Serge/Application.pm index 04ec38cf..80e6aa93 100644 --- a/lib/Serge/Application.pm +++ b/lib/Serge/Application.pm @@ -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) = @_; @@ -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."); } @@ -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"); @@ -172,4 +180,4 @@ sub error { exit($exitstatus); } -1; \ No newline at end of file +1;