Coder Social home page Coder Social logo

Comments (13)

gsscoder avatar gsscoder commented on September 7, 2024

Hi, the problem could be about the wrong specification of the output stream for error reporting.

When you create the CommandLineParser please specify Console.Error. It follows an example:
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));

You can also use the default singleton instance that uses Console.Error by default:
var result = CommandLineParser.Default.ParseArguments(...);

If this doesn't solve this issue, please post a more complete source (or a link to a public download) to repeat the problem.

Regards, Giacomo

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

I've also seen this. I'm working on a patch so you'll probably see a pull request soon. But here's a Gist that illustrates the problem.

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

Well look at that GitHub found my commit anyway. I'll wait a little with making a pull request then.

You can probably see where I was going with the code. A HasValue method has been added, but it currently only works for nullable types. So while it doesn't solve the case of int it would print an error if the option type was int?, or any other type with null as default value.

I thought about adding a specific error string for this but went for simplicity.

from commandline.

gsscoder avatar gsscoder commented on September 7, 2024

Mmmm... I see. Thank you for the Gist source.

args = "".Split(); // prints true and no help text

I think that at least this one is correct because '-z|--zzz' option is not required.

args = "-z 0".Split(); // prints true and no help text

Also this is correct for the parser. It's equal to invoke 'yourapp -z 0'. Why it should be false with help text and errors?

args = "-z".Split(); // prints false and help text, but no errors

I'll start work with this one. False returned is correct but '-z|--zzz' is not boolean so an error should be built...

News A.S.A.P.!

Regards, Giacomo

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

The gist was more about showing the different combinations, with the result in comments for reference. It wasn't my intention to label them right or wrong. Though I agree with you, the first two are correct, the third one should print an error.

I don't know if you've had any time to look at the commit I made. I've been thinking about ways to write a unit test for it but the parser errors aren't really exposed. And doing string searches on the output written doesn't seem like a good approach.

from commandline.

grigmin avatar grigmin commented on September 7, 2024

thanks guys
i look forward to the fix.
this parser looks great. i'm starting to replacing all the in house one we built over the years with this one. it will make our job much easier. :)

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

@jandler create a fork and join the fun :)

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

I would like to see this issue resolved. Take a look at the referencing commit. Thats a unit test which currently fails.

from commandline.

gsscoder avatar gsscoder commented on September 7, 2024

Thanks, I'm working on the project right now!

I'll copy & past after leaving this thread, expect a commit ASAP.

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

I would guess that the fix for this bug involves adding a new property to the ParsingError class. Maybe its time to remove the properties from that class and create one class per error? This will probably make it easier to add new errors. And the boolean properties seems to be mutually exclusive anyway.

from commandline.

gsscoder avatar gsscoder commented on September 7, 2024

I've solved adding a property to OptionInfo to know if the value was set.

This issue is about a non-boolean required option. You can define it, left it without value -> but it still required!

This arise another problem... If an option is Required it MUST not have default value (this not impact the fix) but how do you set a default for a required? Make no sense.

Agree?

from commandline.

alexanderfast avatar alexanderfast commented on September 7, 2024

An required option having its default value is fine, as long as it has a value. For me, the important part of the fix is when the user defined an option but didnt define its value (applies to only non-bool properties).

from commandline.

gsscoder avatar gsscoder commented on September 7, 2024

Check it out... Anyway new test pass (I'd like to write coverage on the subject).

Thanks for help!

from commandline.

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.