Comments (3)
Or for the lazy ExplicitBooleanOptionHandler
is also a way to go.
Simply add handler = ExplicitBooleanOptionHandler.class
to your @Option
annotation.
from args4j.
As to my understanding the idea behind boolean switch is that, if it is
specified amonst the arguments, then it is set to true.
Eg.
program -dosomething something -skipimport
in the above example, there's no point for me to write -skipimport true
as it is already clear from the fact that I specified the parameter, that
it is true (as it is false by default).
Whereas there may be cases, when you want user to explicitly specify
behaviour of the program with the boolean key. For example you're importing
data to database from text file and it is important to specify whether
retries should be performed on error or not. In this case you may want to
have an explicit parameter: -retryonfail
myimport -someparam someparam -retryonfail true
But to implement the above you need to have a string parameter which with
the required flag.
@Option(name="-retryonfail", usage="specify true or false of whether you
want to retry database insertion if the first attempt fails.",
required=true)
private String retryOnFail;
And then you check whether retryOnFail
equals "true"
or `"false"``.
So the bottom line is that, you can accomplish many things with the
combination of boolan or string parameters.
from args4j.
Thanks dimkir for the quick response. Yes I can workaround that issue by using String and parse it to boolean in the code. So in args4j, we can only use boolean variable as a switch but not a key-value pair. I just expect consistent behaviors among all types (boolean, String, int, etc.). Anyway, thanks again.
from args4j.
Related Issues (20)
- Parsing with option value delimiter other than "=" does not work HOT 2
- args4j prints actual values as default values (might contain sensitive information) HOT 4
- deprecated CmdLineException ctor says to use another deprecated ctor
- API changes review for args4j HOT 1
- If bean is null, message "X is not a valid option" occurs
- String array parameters with usage cause NPE when not contained in CLI call HOT 2
- Proper Handling of spaces in attributes
- LICENSE file in 2.33 .jar file
- Is this project still maintained? HOT 2
- Infinite loop with one empty argument
- DelimitedOptionHandler.printDefaultValue() throws NPE (when there are no defaults)
- Space in VALUE breaks --foo=VALUE HOT 1
- usage="", handler = StringArrayOptionHandler.class then parser.printUsage() will crash
- Anyone know of a maintained fork of this? HOT 7
- Also parse environment variables
- How to switch off localization?
- option to have both value and boolean HOT 1
- Cannot find tools.jar
- OSS-Fuzz integration
- Java module support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from args4j.