-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate parser-settings to HelpText (fix #414 and #455) #461
Conversation
Looks like we were heading in similar directions. Still waiting to hear back on my PR #458 but would be sensible to merge these at some point. |
******* PLEASE DO NOT MERGE ****** This change has been merged into #458 |
setting #414 and #455 describe a different issue: The settings of a |
@x789, That is true as you said. Based on your example, It seems that in v2.4.3 and above, configuring parser with
I forked your test case to show 4 different behavior The valid behaviour is by avoiding configuring parser with I think it's better to fix this bug and unify the generation of help either from parser setting or help setting.
Can you modify your PR to fix the bug described above and unify the generation of help either from parser setting or help setting for all Note: , There are 18 test cases for |
@moh-hassan @x789 This PR has already been merged into my PR #458 (as you requested). Making further modifications on this branch seems a bit pointless assuming you are willing to accept my PR ! ;-) |
@NeilMacMullen |
@moh-hassan that bug is not present on my branch. I have added a test to verify that. |
@NeilMacMullen , Good that the bug is not present in your PR. |
@moh-hassan
|
Sweet Fluent interface Code :) |
:-) Yes - you can just add a .SetTextWriter(Console.Error) to the chain if you want to do that |
@NeilMacMullen, please don't get me wrong. I admire your commitment to this project and your approach. I personally like 'fluent' interfaces. But for me, the configuration quoted above is not symmetric. I'm afraid that users can get confused because they have to use two different types of configuration, an
But maybe I have wrong expectations for the class |
@789 Actually I agree with youand appreciate the comments :-) I had already decided to provide fluent modifiers for the parser settings. , not appreciating how they used up to now. (One of the key changes in my PR is to differentiate between the settings used when parsing and the setting used when generating the error text. FWIW, I can't imagine myself every changing AutoHelp/Version but I did want the error text to include the names of acceptable enum values which is currently quite clumsy using the old 'AutoBuild' version. I'm not particularly happy that SetHelpTextConfiguration is required but that's an unfortunate consequence of "burying" a bunch of useful formatting flags in the HelpText class. In the ideal world, these would be hoisted up and the Parser class would be the only thing that users would have to know about. I'm open to ideas on better ways to expose these. Your point about contradictory configurations is good but 1) it's also a problem (actually worse) in the original design and 2) only exists in the new design because of the desire to allow backwards compatibility. I've actually marked all the old methods as Obsolete in my PR but would be quite happy to remove them and call this a breaking change. |
@x789 ,
That is the original PR #256 with commit 5dad6e and merged in v2.3.0 with commit 0db898d It covers the issues #87 and #200 which are not related to issues #414 and #455 and the test cases used have different Assertion objective. What are your suggestions ? |
@moh-hassan Maybe I'm missing something but I don't think the behaviour obtained with the latest changes differs from that desired in #256? In the latest changes, if you specify AutoHelp/AutoVersion=false then:
Are you suggesting that something else should happen? |
|
There is a need for displaying help text with fluent syntax? #39 |
#256 describes the possibility to automatically add a 'help' and 'version' verb/option to the parser. This works as far as only the parser is considered. I think when #256 was integrated, it was not considered that there will also be applications without 'help' and 'version' (see #294, #414 and #455). @NeilMacMullen, @moh-hassan I do not want to stop the discussion about the fluent interface. But we should discuss it as part of #458. I am also confident that we will find a way to introduce a new API without breaking the old one. @moh-hassan The wiki page looks okay to me. It describes the status quo. But it does not cover applications without 'help' and 'version' verbs/options. I consider #414 and #455 to be bugs since the auto-generated help displays verbs/options that are not available. This is confusing and avoids that we can use the auto-help text in applications that do not have 'help' or 'version' verbs/options. If I interpret #294 correctly, others have come across this aspect as well.
|
@x789 - yes I agree that most of this discussion should move to #458 - the only relevance here is that #458 aims to remove the requirement for the user ever to use or know about AutoBuild and therefore uses your changes in a slightly modified version. (Hence I'm keen to know which direction we are going with this - if this PR is merged then I'll just end up having to redo changes.) @moh-hassan
On you wiki you seem to be implying that the suppression of AutoBuild output might happen automatically if AutoHelp was set to false. Personally I think that is a step too far and undesirable for users who want the automatically generated basic usage but who want to supply their own "help" behaviour. I tried your Fiddle and couldn't get to output anything sensible. For example, I commented out the "with.AutoVersion=false;" line and the WithNotParsed line and got absolutely no output. Is that based on the current state of the develop branch? |
@moh-hassan Played some more with your Fiddle and I think 2.5 is broken in some ways that have nothing to do with AutoHelp…
It looks more like the explicit Parser configuration mechanism is broken in this release so I'm not sure the current behaviour is really a good guide for how it should work. If I had to guess, I would assume that when calling the constructor with a no-op function, the ParserSettings object is a new one with a null TextWriter rather than the settings used by Parser.Default. This seems like a very bad disconnect - Parser.Default should give equivalent behavior to new Parser(_=>{}). |
The AutoHelp/AutoVersion feature is added in v2.4.3 as described here and no break in v2.5. The feature is working as intended and tested based on the requirement of @nemec (one of the Authors of the library) @nemec commented on Mar 26, 2018
The tests in the original commit here and in v2.5.0 here For fiddle, there is a problem in redirection of console.Error and duplicate the errors
So AutoHelp/AutoVersion is working as intended and approved by the @nemec. |
@moh-hassan I must admit I am very confused ;-) You were the one who suggested using Fiddle to try and explore the behaviour, with the implication that this PR (and therefore mine) were somehow getting it wrong. Since regression tests are passing on both PRs I'm not really sure what you think should be changed! Perhaps if you could point to a failing test case it would be clearer? (Maybe there is one in an unmerged PR?) Otherwise we just seem to be going round in circles.... The fact that the "default" new Parser constructor behaviour is different from Parser.Default is confusing and something I think should be considered a bug (or at least a poor design decision) but is not directly relevant to how AutoHelp should behave except in as much that it just reveals that the current implementation has too many inconsistencies and it's therefore difficult to use it to establish the "desired" behaviour. I still think the actual behaviour of this PR (and #458) is sensible and desired. Can you explain where you think it isn't? |
The requirements stated above are correctly implemented in CommandLineParser v2.5.0. But in my (and others, see #294 and #414) opinion two important scenarios are missing:
I suspect that if these requirements had been considered in #256, it would have been noticed that the automatically generated |
Indeed, and worth adding there are now unit tests that explicitly check these scenarios.... see line 681 albeit together. In #458 I've broken the combined test into two individual ones for paranoia's sake, but the behaviour is the same. See line 678 |
@NeilMacMullen My concerns is that the intention of the original issues #87 and #200 (disable help/version generation by building their own custom HelpText) which is fixed by Pr #256 are different than the intention of the issues #414 and #455 (which simply hide help/version option from auto generated help) and therefore should have different resolution. BTW, --version and --help are LNX/POSIX standard in all commandLine utilities (this library respect and implement this standard ) and the requirement of the issues #414 and #455 for hiding them may violate this standard. Any enhancement or Fluent interface API to HelpText is welcome and it's needed in #39 and can be completed with this PR and yours without Breaking Change or obsolete AutoBuild. |
I think this is a misunderstanding. This pull request #461 has nothing to do with the configuration of
Unfortunately, CommandLineParser violates the POSIX standard by allowing multi-character options, double-dashes and verbs. Chapter 12.2 is very precise. I wasn't aware that CommandLineParser 'enforces' the presence of help and version. If this restriction is really wanted, it should be documented in a prominent place. |
@x789 The Readme link this Getopt ref Can you give me an example of the violation of the multi-character options?
Yes, you are correct. Attention will be take for the documentation and I hope contribution in Wiki. |
These two scenarios are described in the wiki in In these scenarios, parser consider --help and --version an unknown option and raise an error Developers can handle these cases (if needed) in:
and show their own custom help/version or custom error screen |
@moh-hassan
Thank you for referring to the getopt-documentation. I can understand your point of view now.
|
With the knowledge gathered in this discussion, I have once again read through the complete documentation of the module. @moh-hassan I can now completely understand your argumentation. Some points are hidden between the lines in the documentation. In my experience, however, it is normal for a developer documentation not to contain and explain every (implicit) decision made. Here's my suggestion on how to proceed:
|
@x789 |
#414 and #455 don't look like "simply hiding" for me. Hiding an unavailable command is correct. Hiding an available command is a bug. So the main problem is that the pull request #256 didn't test generation of error message help properly. @x789's suggestion of completely separating availability as a command and availability on the help screen sounds really weird to me, to be frank. Maybe I'm missing something or I'm unaware of technical limitations, but that's not what users of command line programs would ever expect.
Removing "version" and "help" completely is bad, but I think it should be allowed. The library is not standards police.
I can't access wiki for some reason, GitHub keeps redirecting me to the front page of the fork. |
This fixes issues #414 and #455 (value of
AutoHelp
andAutoVersion
are ignored byHelpText
)This fix does not change the public interface. It is achieved by overloading
HelpText.AutoBuild
. If aParameterSettings
object is passed, the values it contains are used. If noParameterSettings
are passed toAutoBuild
, help and version are always displayed.