GithubHelp home page GithubHelp logo

boolean option cannot have value about args4j HOT 3 OPEN

kohsuke avatar kohsuke commented on June 18, 2024
boolean option cannot have value

from args4j.

Comments (3)

MikeMatrix avatar MikeMatrix commented on June 18, 2024 11

Or for the lazy ExplicitBooleanOptionHandler is also a way to go.
Simply add handler = ExplicitBooleanOptionHandler.class to your @Option annotation.

from args4j.

dimkir avatar dimkir commented on June 18, 2024 3

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.

simon-zhou avatar simon-zhou commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.