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 | |
parent | 4dcd4d96b7b1a2a0880a374f142c160df259c648 (diff) | |
download | mangemanche-bfaee2787b9e955d0f7231cbc1fa045d6d892d60.tar.gz mangemanche-bfaee2787b9e955d0f7231cbc1fa045d6d892d60.tar.bz2 |
Rewrite --help handling
-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 @@ -7,6 +7,7 @@ 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'; @@ -20,19 +21,17 @@ sub new { 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, 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 @@ -6,6 +6,8 @@ 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, @@ -13,11 +15,29 @@ use constant { 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; @@ -30,9 +50,7 @@ sub new { -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, |