Perl Pod::用法帮助格式化
我想为我的Perl脚本正确设置帮助消息的格式,如果可能的话,可以使用标准模块,如Perl Pod::用法帮助格式化,perl,options,command-line-interface,Perl,Options,Command Line Interface,我想为我的Perl脚本正确设置帮助消息的格式,如果可能的话,可以使用标准模块,如Pod::Usage。不幸的是,我并不真正喜欢pod2usage的输出格式。例如,使用grep我可以获得以下帮助结构: $ grep --help Usage: grep [OPTION]... PATTERN [FILE]... Search for PATTERN in each FILE or standard input. PATTERN is, by default, a basic regular exp
Pod::Usage
。不幸的是,我并不真正喜欢pod2usage的输出格式。例如,使用grep
我可以获得以下帮助结构:
$ grep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c
Regexp selection and interpretation:
-E, --extended-regexp PATTERN is an extended regular expression (ERE)
-F, --fixed-strings PATTERN is a set of newline-separated fixed strings
-G, --basic-regexp PATTERN is a basic regular expression (BRE)
-P, --perl-regexp PATTERN is a Perl regular expression
但是这与Pod::Usage
非常不同,我得到了不需要的\n
和\t
:
$ ./sample.pl --help
Usage:
sample [options] [file ...]
This program will read the given input file(s) and do something useful
with the contents thereof.
Options:
--help
Print a brief help message and exits.
--man
Prints the manual page and exits.
我想以传统方式修改我的帮助格式,即不使用\n
和不使用\t
。事实上,我正在寻找一种解决方案,使我能够写下以下内容:
__END__
=head1 SYNOPSIS
sample [options] [file ...]
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=head1 OPTIONS
=item B<-h,--help>
Print a brief help message and exits.
=item B<-v,--version>
Prints the version and exits.
=cut
不是这个:
Usage:
sample [options] [file ...]
This program will read the given input file(s) and do something useful
with the contents thereof.
Options:
-h,--help Print a brief help message and exits.
-v,--version Prints the version and exits.
有线索吗 您可以尝试两件事: 用户需要将其切换到Pod::Text,这是一个更简单的格式化程序 或
Pod::Text
也有一些格式选项,例如左边距、缩进级别、页面宽度,这可能会使它更符合您的喜好。当您使用=item
时,您应该在它前面加上=over x
,其中x
是您要移动的距离。完成项目后,需要使用=back
。如果=over x
足够长,则该项目的段落将与=item
打印在同一行上。我到处玩,发现=20多个看起来很不错:
use strict;
use warnings;
use Pod::Usage;
pod2usage( -verbose => 1);
=pod
=head1 SYNOPSIS
sample [options] [file ...]
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=head1 OPTIONS
=over 20
=item B<-h>, B<--help>
Print a brief help message and exits.
=item B<-v>, B<--version>
Prints the version and exits.
=back
=cut
在POD中使用v,-version
的东西并不能让它以漂亮的三列格式打印。您可以做的是在-h
和-help
之间留出更多的空间,就像我在上面所做的那样,以提高可读性
记住,重要的是POD中的数据,而不是绝对格式。使用格式使其易于阅读,但不要过分强调细节
我强烈建议您使用旧的标准手册页布局(这是pod2use
假定的)
use strict;
use warnings;
use Pod::Usage;
pod2usage( -verbose => 1);
=pod
=head1 SYNOPSIS
sample [options] [file ...]
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=head1 OPTIONS
=over 20
=item B<-h>, B<--help>
Print a brief help message and exits.
=item B<-v>, B<--version>
Prints the version and exits.
=back
=cut
Usage:
sample [options] [file ...]
This program will read the given input file(s) and do something useful
with the contents thereof.
Options:
-h, --help Print a brief help message and exits.
-v, --version Prints the version and exits.