apache-commons-cli

Can Apache Commons CLI options parser ignore unknown command-line options?

五迷三道 提交于 2019-11-29 09:09:26
I am writing a Java application that takes command line arguments which are processed using Apache Commons CLI with the GnuParser. For reasons that are not interesting to get into, I would like it to silently ignore unknown command line options instead of throwing a ParseException but I don't see a way to do that. I see that there is a stopAtNonOption boolean option on GnuParser.parse() but what I want is more like ignoreAtNonOption where it will keep processing options after encountering an unknown token. I could implement my own parser to accomplish this but I'm surprised there isn't this

Commons CLI required groups

不羁岁月 提交于 2019-11-28 20:14:49
I am writing command line application in Java and I've chosen Apache Commons CLI to parse input arguments. Let's say I have two required options (ie. -input and -output). I create new Option object and set required flag. For now it's all good. But I have third, not required option , ie. -help. With settings that I've mentioned, when user wants to show help (use -help option) it says "-input and -output" are required. Is there any way to implement this (via Commons CLI API, not simple if (!hasOption) throw new XXXException()). Emmanuel Bourg In this situation you have to define two sets of

Can Apache Commons CLI options parser ignore unknown command-line options?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 02:51:31
问题 I am writing a Java application that takes command line arguments which are processed using Apache Commons CLI with the GnuParser. For reasons that are not interesting to get into, I would like it to silently ignore unknown command line options instead of throwing a ParseException but I don't see a way to do that. I see that there is a stopAtNonOption boolean option on GnuParser.parse() but what I want is more like ignoreAtNonOption where it will keep processing options after encountering an

How to fetch parameters when using the Apache Commons CLI library

喜夏-厌秋 提交于 2019-11-27 14:19:52
I'm using the Apache Commons CLI to handle command line arguments in Java. I've declared the a and b options and I'm able to access the value using CommandLine.getOptionValue() . Usage: myapp [OPTION] [DIRECTORY] Options: -a Option A -b Option B How do I declare and access the DIRECTORY variable? Use the following method: CommandLine.getArgList() which returns whatever's left after options have been processed. It may be better to use another Option (-d) to identify directory which is more intuitive to the user. Or the following code demonstrates getting the remaining argument list public

Commons CLI required groups

烂漫一生 提交于 2019-11-27 12:48:35
问题 I am writing command line application in Java and I've chosen Apache Commons CLI to parse input arguments. Let's say I have two required options (ie. -input and -output). I create new Option object and set required flag. For now it's all good. But I have third, not required option , ie. -help. With settings that I've mentioned, when user wants to show help (use -help option) it says "-input and -output" are required. Is there any way to implement this (via Commons CLI API, not simple if (

How to fetch parameters when using the Apache Commons CLI library

怎甘沉沦 提交于 2019-11-26 16:40:52
问题 I'm using the Apache Commons CLI to handle command line arguments in Java. I've declared the a and b options and I'm able to access the value using CommandLine.getOptionValue() . Usage: myapp [OPTION] [DIRECTORY] Options: -a Option A -b Option B How do I declare and access the DIRECTORY variable? 回答1: Use the following method: CommandLine.getArgList() which returns whatever's left after options have been processed. 回答2: It may be better to use another Option (-d) to identify directory which