App-PFT

 view release on metacpan or  search on metacpan

bin/pft-show  view on Meta::CPAN


=head1 SYNOPSIS

B<pft show> [B<-v>]

=head1 DESCRIPTION

Once the site is built with L<pft-make(1)>, it can be visualized locally by
invoking B<pft show>.

This command is really just syntactic sugar for:

    $BROWSER ROOT/build/index.html

Where C<$BROWSER> depends on the C<pft.yaml> configuration file (see
L<pft-init(1)>) or by the C<$BROWSER> environment variable if no browser is
defined by the configuration.

=head1 OPTIONS

=over

=item B<--browser>=I<command>

The browser can be specified by name (e.g. C<firefox>) or as a L<sh(1)>
command line, where C<%s> is replaced with the file name
(e.g. C<firefox '%s'>).

This flag overrides the C<system.browser> setting in the C<pft.yaml>
file. If neither the flag nor the setting are specified, the C<$BROWSER>
environment variable will be honored.

=item B<--help> | B<-h>

Show this help.

=back

=head1 SEE ALSO

L<pft-init(1)>, L<pft-make(1)>

=cut

use v5.16;
use strict;
use warnings;
use utf8;

use feature qw/say/;

use Pod::Usage;
use File::Spec;

use Getopt::Long;
Getopt::Long::Configure ("bundling");

use PFT::Tree;

my $tree = eval{ PFT::Tree->new } || do {
    say STDERR $@ =~ s/ at.*$//rs;
    exit 3
};

my $conf = eval{ $tree->conf } || do {
    say STDERR 'Configuration error: ', $@ =~ s/ at.*$//rs;
    exit 4
};

my $browser = $conf->{system}{browser} || $ENV{BROWSER};
my $verbose = 0;
GetOptions(
    'browser=s' => \$browser,
    'help|h' => sub {
        pod2usage
            -exitval => 1,
            -verbose => 2,
            -input => App::PFT::help_of 'show',
    }
) or exit 1;

my $index = File::Spec->catfile($tree->dir_build, 'index.html');

unless ($index) {
    say STDERR 'Need to build first, use pft make';
    exit 1;
}

if ($browser =~ s/(?<!%)%s/$index/g) {
    system($browser)
} else {
    system($browser, $index)
}



( run in 3.445 seconds using v1.01-cache-2.11-cpan-a49fcb8fa48 )