【发布时间】:2014-07-03 07:11:46
【问题描述】:
我想为我的 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 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.
不是这个:
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.
有什么线索吗?
【问题讨论】:
标签: perl options command-line-interface