我要疯了,所以我在这里:)
我正在尝试为我的Perl程序制作文档,但我从未设法让Getopt :: Long和pod2man工作。
这是我为测试目的编写的一个简单程序:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
Getopt::Long::Configure ("bundling");
my $option = "";
my $verbose = 1;
my $quiet = 0;
my $man = 0;
my $help = 0;
GetOptions (
"option=s" => \$option,
"verbose" => sub { $verbose = 1; $quiet = 0 },
"quiet|noverbose" => sub { $verbose = 0; $quiet = 1 },
"help|?" => \$help,
man => \$man
) or pod2usage("Error in command line.\n");
pod2usage(1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;
print "my programm here\n";
__END__
=head1 NAME
my-prog.pl - Customized mysqldump utility
=head1 SYNOPSIS
my-prog.pl [OPTIONS]
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.
=item B<--option>
Option description
=item B<--verbose>
Option description
=back
=head1 DESCRIPTION
B<my-prog.pl> is doing something.
=head1 AUTHOR
B<Me>
=cut
不幸的是,当我这样做时:
./ my-prog.pl --help
什么都没有出现。更糟糕的是,当我这样做时:
./ my-prog.pl --man
我得到了一个包含我整个程序的诅咒页面(我的程序的每一行,而不仅仅是帮助手册)。
在我发疯之前,回过头来定制一个print_help()子程序,你能帮我吗?
提前致谢:)
编辑1:感谢@toolic修改了程序。现在,我的--help工作正常,但是 - man正在向我展示我的程序的完整源代码,就像一个“man”页面。我在Debian Wheezy上用Perl 5.14.2运行这个脚本。
答案 0 :(得分:6)
您需要更改您的POD。添加空白行,仅对逐字段落使用缩进。请参阅perldoc perlpod。我的编辑器在POD的语法高亮方面做得很好,使错误更加明显。
=head1 NAME
my-prog.pl - Customized mysqldump utility
=head1 SYNOPSIS
my-prog.pl [OPTIONS]
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.
=item B<--option>
Option description
=item B<--verbose>
Option description
=back
=head1 DESCRIPTION
B<my-prog.pl> is doing something.
=head1 AUTHOR
B<Me>
=cut
答案 1 :(得分:1)
在我的几台计算机(Debian 9)上,它依赖于 perldoc 的存在。我试图看到我的脚本完整的手册,但在我返回命令行后得到源代码加上小通知:
$ ./get-structure.pl --man
You need to install the perl-doc package to use this program.
我已经安装了perldoc,现在我看到了我需要的东西:
$ perldoc ./get-structure.pl
You need to install the perl-doc package to use this program.
$ sudo apt install perl-doc
...
$ ./get-structure.pl --man
SYNOPSIS
./structure-to-csv.pl [options]
OPTIONS
--departments
Specify output file for departments.
...