Java 如何在getopt类中指定连字符作为选项参数
我必须给“-”作为选项参数 Getopt类 我的代码如下Java 如何在getopt类中指定连字符作为选项参数,java,Java,我必须给“-”作为选项参数 Getopt类 我的代码如下 Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log while((opt = g.getopt()) != -1) { switch (opt) { case 'f'://To set file name(if above is not specified) fileNameW
Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log
while((opt = g.getopt()) != -1)
{
switch (opt)
{
case 'f'://To set file name(if above is not specified)
fileNameWithPath = getAndCheckOptArg(fFlag, opt, g);
fFlag = true;
break;
case 's'://To set the header
String separator = getAndCheckOptArg(hFlag, opt, g);
hFlag = true;
breakk;
case '?':
usage("Invalid option" + opt + " option");
break;
}
}
在参数中,我希望将其命名为-s“-”,但它显示了一些错误,例如无效选项。有什么方法可以做到这一点吗?--
中有一个特殊的含义
用户可以强制getopt()停止扫描带有特殊参数“-”的命令行。在“-”之前出现的任何元素都将按正常方式进行扫描和排列。“-”之后的任何元素都将按原样作为非选项argv元素返回。例如,“foo-a--bar-d”将返回选项“a”,然后返回-1。optind将指向“foo”、“bar”和“-d”作为非选项argv元素。getopt()将丢弃“-”
因此,恐怕您无法完成此操作。您可以使用
-s-
(无空格)来完成此操作。我不知道Getopt是否允许这样做