-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
getoptX Help Messages for getopt #2072
Conversation
anyone? |
|
||
/** The result of the $(D getoptXHelp) function. | ||
*/ | ||
alias Tuple!(string, "optShort", string, "optLong", string, "help") Option; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't get the point of wanting to pull out Tuples for things like this, when:
struct Option {string optShort; string optLong; string help}
Works just as well. And is POD. This is abusive use of Tuples, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, I will change that.
Not looking in great detail but why can't getopt be extended as is? |
It could be extended, but it would break the current api. |
I don't understand why. The discussion we had in #1840 suggests we don't have to break anything. |
int help;
getopt("h|help", &heig)
... "h|help" might have two meanings |
Just check if "h|help" is already used. I think a sane default would be to issue a compile error in case there is both a user-defined "h|help" option AND documentation strings. It won't break a thing. |
I don't like this fix. It doesn't even fix my example. I really don't want to stick such code into getopt. getopt has an easy, forthcoming api and adding the help stuff to it would make it much more complicated IMO. I don't think that is a good trade-off. IMO getoptEx is the right way to go here. |
You don't have to.
It does because by definition there is no user code out there that does BOTH define an option 'h' and uses help strings (nobody can use them yet). |
I don't see why you don't have to fix it. My argument is that mixing getopt and getoptEx will break the api. Of course, currently no one can use this, but if an getopt mix gets merged everyone will use this. |
I'm really looking forward to getting this into phobos. It will allow me to remove a lot of custom code. Can we get this into the next release? |
@burner take a look at the referenced pull request - it does extend getopt in backward compatible way, what was the exact reason that you say it couldn't be done? |
it requires that h|help are not in use. It breaks the semantic of the getopt api. |
It however only needs that if and only if there were text messages describing each option. It in turn this means that nothing could break as long as you don't treat "h|help' specially when no descriptions are given (and all of the code there is doesn't have them - so it can't break) |
If the concern is that somehow might already be using |
I will move the stuff to getopt |
it is now part of getopt in a none breaking way |
|
||
If an option string is followed by another string, this string serves as an | ||
description for this option. The function $(D getopt) returns a struct of type | ||
$(D GetoptRslt). This return value contains information about all passed options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See no gain in abbr-itng GetotpResult :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, getopt is already an abbr. But two chars more will not kill me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, Rslt is a bit too much. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Can we get this into 2.066? 👍 |
That would be awesome. But nobody other than @DmitryOlshansky has taken a look at the source lately. |
@@ -70,12 +70,12 @@ Color color; | |||
|
|||
void main(string[] args) | |||
{ | |||
getopt( | |||
auto helpInformation = getopt( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the progress? Adding unused variable to an example is silly. Either use it later or drop this variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix that, thanks?
what do you mean by progress? getoptx is now part of getopt, without breaking getopt usage where h or help is already in use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that if the change was intentional (looks like not) then my question was if it does anything new, i.e. what is the progress compared to the previous version of unittest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change should show that getopt returns something. I just forgot to show what this something does and how to use it.
Auto-merge toggled on |
thank you |
getoptX Help Messages for getopt
@AndrewEdwards - Would it be possible to get this into the 2.066 release? |
@jcrapuchettes https://issues.dlang.org/show_bug.cgi?id=13072, |
And considering this is neither bug nor regression it should wait for 2.067 |
We have a need for this here at EMSI and having it in the 2.066 release would be a big benefit to us. |
Would it help preparing separate 2.066 distribution for internal EMSI usage with this changeset included? |
We prefer to use stock releases. If this change can't make it into 2.066, we can wait till 2.067. |
I believe that making any exceptions in release process by company requests is the wrong thing to do, it creates certain expectations and does not scale with increased user base. If we start adding features during beta right now, when do we stop? Having custom distributions for such needs is quite a common practice to address this problem if some changes are really important. We actually do this in Sociomantic despite having 0 difference with D1 upstream (and despite the fact it is mostly frozen). I don't want to sound like I don't think your needs are not important but we need to find a good compromise between addressing the needs of commercial users and keeping upstream community development process adamant. |
I understand. We currently use a workaround and will plan on continuing to use that till the next release. |
This is actually amazing. Just found out about it now, should make it to the changelog for 2.067. |
This pull request introduced a regression: |
the getopt module is lacking help information. This PR add getoptX. getoptX allows to specify help information, in string from, after the option. It does not change anything in the getopt implementation. getoptX passes all option strings and option refs to getopt. Additionally, it returns a tuple containing a bool, that indicates if "--help|-h" where passed in the args, and an array of Option, that contains the available options. A very simple help page printer is present in form of defaultGetoptXPrinter.
as requested by @jcrapuchettes Required was added to mark options as required options.
https://d.puremagic.com/issues/show_bug.cgi?id=11876
previously AndrejMitrovic was working on this. In conjunction with him, I'm taking over (see bugzilla).
#1840 AndrejMitrovic version
#1030 jkm version
https://www.bountysource.com/issues/1327158-getopt-improvements-by-igor-lesik