diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-03-02 15:44:24 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-03-02 15:44:24 +0000 |
commit | bfaee2787b9e955d0f7231cbc1fa045d6d892d60 (patch) | |
tree | 9b19721d4b561d6b78c1ea03957ce7a719ae099a /lib | |
parent | 4dcd4d96b7b1a2a0880a374f142c160df259c648 (diff) | |
download | mangemanche-bfaee2787b9e955d0f7231cbc1fa045d6d892d60.tar.gz mangemanche-bfaee2787b9e955d0f7231cbc1fa045d6d892d60.tar.bz2 |
Rewrite --help handling
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/Ping903.pm | 9 | ||||
-rw-r--r-- | lib/App/Ping903/Command.pm | 26 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lib/App/Ping903.pm b/lib/App/Ping903.pm index 7bb18f0..2a39391 100644 --- a/lib/App/Ping903.pm +++ b/lib/App/Ping903.pm @@ -4,12 +4,13 @@ use warnings; use Getopt::Long qw(:config gnu_getopt no_ignore_case require_order); use Pod::Man; use Pod::Usage; use Pod::Find qw(pod_where); use Net::Ping903; use App::Ping903::Command ':exit_codes'; +use File::Basename; our $VERSION = '0.4.90'; my $DEFAULT_URL = 'http://localhost:8080'; sub new { @@ -17,25 +18,23 @@ sub new { my $config_file; my $url; my $config = {}; GetOptions( 'shorthelp|?' => sub { - pod2usage(-input => pod_where({-inc => 1}, __PACKAGE__), + pod2usage(-input => pod_where({-inc => 1}, $class), -verbose => 99, -sections => [qw(NAME SYNOPSIS COMMANDS)], -exitstatus => EX_OK) }, 'help' => sub { - pod2usage(-exitstatus => EX_OK, - -input => pod_where({-inc => 1}, __PACKAGE__), - -verbose => 2) + App::Ping903::Command::mandoc($class, basename($0)), }, 'usage' => sub { pod2usage(-exitstatus => EX_OK, - -input => pod_where({-inc => 1}, __PACKAGE__), + -input => pod_where({-inc => 1}, $class), -verbose => 0) }, 'config|c=s' => \$config_file, 'url|u=s' => \$url ) or exit(EX_USAGE); diff --git a/lib/App/Ping903/Command.pm b/lib/App/Ping903/Command.pm index 516f1a6..bd1a85f 100644 --- a/lib/App/Ping903/Command.pm +++ b/lib/App/Ping903/Command.pm @@ -3,39 +3,57 @@ use strict; use warnings; use Getopt::Long; use Pod::Usage; use Pod::Find qw(pod_where); use Carp; use parent 'Exporter'; +use Pod::Man; +use File::Temp qw(tempfile); use constant { EX_OK => 0, EX_FAIL => 1, EX_USAGE => 2 }; -our @EXPORT_OK = qw(EX_OK EX_FAIL EX_USAGE); +our @EXPORT_OK = qw(EX_OK EX_FAIL EX_USAGE mandoc); our %EXPORT_TAGS = ( 'exit_codes' => [ qw(EX_OK EX_FAIL EX_USAGE) ] ); +sub mandoc { + my ($class, $name) = @_; + + my $input = pod_where({-inc => 1}, $class); + unless ($name) { + ($name = $class) =~ s/.*:://; + } + my $parser = Pod::Man->new(name => $name, + center => 'Ping903 control command', + release => 'Mangemanche'); + my ($fh,$filename) = tempfile(); + $parser->parse_from_file($input, $filename); + close($fh); + system("man $filename"); + unlink($filename); + exit(0); +} + sub new { my ($class, $com, $agent, %opts) = @_; my $self = bless { progname => $com, agent => $agent }, $class; $self->{options} = {}; $self->{optdef}{'shorthelp|?'} = sub { pod2usage(-message => $class->pod_usage_msg, -input => pod_where({-inc => 1}, $class), -exitstatus => EX_OK) }; $self->{optdef}{help} = sub { - pod2usage(-exitstatus => EX_OK, - -verbose => 2, - -input => pod_where({-inc => 1}, $class)) + mandoc($class); }; $self->{optdef}{usage} = sub { pod2usage(-exitstatus => EX_OK, -verbose => 0, -input => pod_where({-inc => 1}, $class)) }; |