Skip to content
Open
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
28 changes: 27 additions & 1 deletion bin/plerdall
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use Plerd::Util;
use Plerd::Init;
use Cwd;
use Path::Class::Dir;
use Pod::Usage qw(pod2usage);

use Text::Wrap qw(wrap);

Expand All @@ -26,13 +27,26 @@ my $process_webmentions = 0;
my $rebuild_webmentions = 0;
my $config_file;
my $init_path;
my $help;
my $show_version;
GetOptions(
'send-webmentions' => \$webmention_enabled,
'process-webmentions' => \$process_webmentions,
'rebuild-webmentions' => \$rebuild_webmentions,
'config=s' => \$config_file,
'init:s' => \$init_path,
);
'help' => \$help,
'version' => \$show_version,
) or pod2usage( -exitval => 2, -verbose => 0 );

if ( $help ) {
pod2usage( -exitval => 0, -verbose => 1 );
}

if ( $show_version ) {
print "plerdall is part of Plerd $Plerd::VERSION\n";
exit 0;
}

if ($process_webmentions or $rebuild_webmentions) {
die "Plerd ended its experimental Webmention receipt support in version "
Expand Down Expand Up @@ -115,6 +129,18 @@ available online at L<https://github.com/jmacdotorg/plerd#plerd>.

=head1 OPTIONS

=head2 help

bin/plerdwatcher --help

Print this documentation and exit.

=head2 version

bin/plerdwatcher --version

Print the running version of Plerd and exit.

=head2 config

bin/plerdall --config=/path/to/plerd.conf
Expand Down
28 changes: 27 additions & 1 deletion bin/plerdwatcher
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,32 @@ use App::Daemon qw( daemonize );
use Try::Tiny;
use Log::Log4perl qw( :easy );
use Getopt::Long;
use Pod::Usage qw(pod2usage);

use Plerd;
use Plerd::Util;

my $webmention_enabled = 0;
my $webmention_port = 0;
my $config_file;
my $help;
my $show_version;
GetOptions(
'config=s' => \$config_file,
'send-webmentions' => \$webmention_enabled,
'receive-webmentions=i' => \$webmention_port,
);
'version' => \$show_version,
'help' => \$help,
) or pod2usage( -exitval => 2, -verbose => 0 );

if ( $help ) {
pod2usage( -exitval => 0, -verbose => 1 );
}

if ( $show_version ) {
print "plerdwatcher is part of Plerd $Plerd::VERSION\n";
exit 0;
}

if ($webmention_port) {
die "Plerd ended its experimental Webmention receipt support in version "
Expand Down Expand Up @@ -163,6 +177,18 @@ available online at L<https://github.com/jmacdotorg/plerd#plerd>.

=head1 OPTIONS

=head2 help

bin/plerdwatcher --help

Print this documentation and exit.

=head2 version

bin/plerdwatcher --version

Print the running version of Plerd and exit.

=head2 config

bin/plerdall --config=/path/to/plerd.conf
Expand Down
104 changes: 104 additions & 0 deletions t/cli_options.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use warnings;
use strict;
use Test::More;
use Capture::Tiny ':all';

use FindBin;
use lib "$FindBin::Bin/../lib";

use Plerd;

my $plerdall = "$FindBin::Bin/../bin/plerdall";

# --version prints the Plerd version and exits zero, without requiring
# a config file to be present.
{
my ($stdout, $stderr, $exit) = capture {
system( $^X, '-I', "$FindBin::Bin/../lib/", $plerdall, '--version' );
};

is( $exit, 0, '--version exits zero.' );
like(
$stdout,
qr/\Q$Plerd::VERSION\E/,
'--version output mentions the Plerd version number.',
);
is( $stderr, '', '--version produces no error output.' );
}

# --help prints usage information and exits zero, without requiring
# a config file to be present.
{
my ($stdout, $stderr, $exit) = capture {
system( $^X, '-I', "$FindBin::Bin/../lib/", $plerdall, '--help' );
};

is( $exit, 0, '--help exits zero.' );
like(
$stdout,
qr/plerdall/i,
'--help output mentions the program name.',
);
like(
$stdout,
qr/--config/,
'--help output documents the --config option.',
);
is( $stderr, '', '--help produces no error output.' );
}

# An unrecognized option should still fail informatively (regression
# check for the old "Unknown option: help"-with-a-config-error mess).
{
my ($stdout, $stderr, $exit) = capture {
system(
$^X, '-I', "$FindBin::Bin/../lib/",
$plerdall, '--this-is-not-a-real-option',
);
};

isnt( $exit, 0, 'An unrecognized option exits non-zero.' );
}

# plerdwatcher --version prints the Plerd version and exits zero,
# without requiring a config file or launching the daemon.
{
my $plerdwatcher = "$FindBin::Bin/../bin/plerdwatcher";

my ($stdout, $stderr, $exit) = capture {
system( $^X, '-I', "$FindBin::Bin/../lib/", $plerdwatcher, '--version' );
};

is( $exit, 0, 'plerdwatcher --version exits zero.' );
like(
$stdout,
qr/\Q$Plerd::VERSION\E/,
'plerdwatcher --version output mentions the Plerd version number.',
);
is( $stderr, '', 'plerdwatcher --version produces no error output.' );
}

# plerdwatcher --help prints usage information and exits zero, without
# requiring a config file or launching the daemon.
{
my $plerdwatcher = "$FindBin::Bin/../bin/plerdwatcher";

my ($stdout, $stderr, $exit) = capture {
system( $^X, '-I', "$FindBin::Bin/../lib/", $plerdwatcher, '--help' );
};

is( $exit, 0, 'plerdwatcher --help exits zero.' );
like(
$stdout,
qr/plerdwatcher/i,
'plerdwatcher --help output mentions the program name.',
);
like(
$stdout,
qr/--config/,
'plerdwatcher --help output documents the --config option.',
);
is( $stderr, '', 'plerdwatcher --help produces no error output.' );
}

done_testing;