Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Help from the command line

by robsv (Curate)
on Feb 01, 2001 at 21:51 UTC ( #55761=snippet: print w/replies, xml ) Need Help??
Description: I've started adding a brief "self help" snippet in code that I write for others. This allows them to enter command -help from the command line and get the POD doc. We're still on Perl 5.005 here, so I'd guess that the warnings either don't appear in 5.6, or at least can be ignored with no warnings.
#!/usr/local/bin/perl -w

use strict;
use Getopt::Long;
use Pod::Text;


(my $PROGRAM = (split('/',$0))[-1]) =~ s/\..*$//;
my $USAGE = <<__EOT__;
Usage: $PROGRAM [-help]
__EOT__


my $HELP;

# Get the command-line parameters
GetOptions("help" => \$HELP)
  or die($USAGE);

if ($HELP)
{
  $^W = 0;  # Pod::Text throws warnings
  pod2text($0);
  exit(0);
}

# Continue with the rest of the program

# ********************************************************
# * POD documentation
# ********************************************************
__END__

=head1 NAME

helpme - an example of command-line help

=head1 SYNOPSIS

helpme [-help]

=head1 DESCRIPTION

Put your description here!

=head1 EXIT STATUS

The following exit values are returned:

   0  Successful completion

  -1  An error occurred

=head1 AUTHOR INFORMATION

Author: Elmer Fudd

Address bug reports and comments to:
Elmer.Fudd@killthewabbit.com

=cut
Replies are listed 'Best First'.
Re: Help from the command line
by btrott (Parson) on Feb 01, 2001 at 22:36 UTC
    You might also want to check out Pod::Usage, which uses your POD to print out usage messages (similar in spirit to what your code does, but it doesn't print the entire POD).

    You can have it print out your SYNOPSIS section, and optionally an ARGUMENTS and/or OPTIONS section.

    Here's an example from the docs:

    use Getopt::Long; use Pod::Usage; my $man = 0; my $help = 0; ## Parse options and print usage if there is a syntax error, ## or if usage was explicitly requested. GetOptions('help|?' => \$help, man => \$man) or pod2usage(2); pod2usage(1) if $help; pod2usage(-verbose => 2) if $man; ## If no arguments were given, then allow STDIN to be used only ## if it's not connected to a terminal (otherwise print usage) pod2usage("$0: No files given.") if ((@ARGV == 0) && (-t STDIN)); __END__ =head1 NAME sample - Using GetOpt::Long and Pod::Usage =head1 SYNOPSIS sample [options] [file ...] Options: -help brief help message -man full documentation =head1 OPTIONS =over 8 =item B<-help> Print a brief help message and exits. =item B<-man> Prints the manual page and exits. =back =head1 DESCRIPTION B<This program> will read the given input file(s) and do something useful with the contents thereof. =cut
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://55761]
help
Chatterbox?
[james28909]: @choroba yes they do but for some reasom when i try to pipe the output of youtube-dl to ffmpeg, it fails. hence the work around lol
[RonW]: james28909: Interesting trick
[choroba]: The theme is "High-end Perl", so both my talks are antitheses: "Low-end Perl" and "How to almost win a T-shirt in a programming contest"
[RonW]: I wonder if that's a CMD.exe limitation or a Windows limitation
[james28909]: what i am trying to accomplish is piping the output of ffmpeg to yet another encryption routine using libsodium. and hopefully once that is done i will be able to forward the packets to discord servers
[RonW]: choroba: Please define "high end" and "low end"
[LanX]: choroba: subversive (as usual ;)
[james28909]: i dunno, if i didnt have so little experience in linux i would swap. but it would be to much of a learning curve for me right now.
[choroba]: Low-end is defined as the Perl that generates millions of income
[choroba]: sorry, that's high-end, of coursse

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (16)
As of 2017-05-22 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?