Comments (13)
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.
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.
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.
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.
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.
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.
@jandler create a fork and join the fun :)
from commandline.
I would like to see this issue resolved. Take a look at the referencing commit. Thats a unit test which currently fails.
from commandline.
Thanks, I'm working on the project right now!
I'll copy & past after leaving this thread, expect a commit ASAP.
from commandline.
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.
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.
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.
Check it out... Anyway new test pass (I'd like to write coverage on the subject).
Thanks for help!
from commandline.
Related Issues (20)
- Support for default verb? HOT 7
- Is version 2 still beta? HOT 3
- Cannot use 2 verbs at the same time HOT 5
- Mutual exclusive option is not enforced (even when settings.MutuallyExclusive == true) HOT 3
- Has the approach to verbs in v2 changed? HOT 6
- THIS REPO GOING DEFUNCT, please submit issues/pull requests to https://github.com/commandlineparser/commandline HOT 2
- Argument value with dash not accepted when using single-dash key HOT 1
- Good, except parsing doesn't work HOT 1
- Parser state HOT 1
- Using --help HOT 1
- Inverse order of FlatternHierarchy HOT 1
- Enum Parsing Is Failing HOT 2
- Migrating from 2.3.0 to 2.4.3 HOT 3
- Please support older .NET framework versions
- Unable to parse TimeSpan given from FormatCommandLine HOT 2
- Order of options where there are list options and values HOT 1
- Group where none or all options must be provided HOT 1
- Fast HOT 1
- (Tool's);
- Tv
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 commandline.