Skip to content
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

Merged
merged 1 commit into from
Jul 10, 2014
Merged

getoptX Help Messages for getopt #2072

merged 1 commit into from
Jul 10, 2014

Conversation

burner
Copy link
Member

@burner burner commented Apr 7, 2014

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

@burner burner changed the title getoptX Help Messages for getOp getoptX Help Messages for getopt Apr 7, 2014
@burner
Copy link
Member Author

burner commented Apr 15, 2014

anyone?


/** The result of the $(D getoptXHelp) function.
*/
alias Tuple!(string, "optShort", string, "optLong", string, "help") Option;
Copy link
Collaborator

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.

Copy link
Member Author

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.

@DmitryOlshansky
Copy link
Member

Not looking in great detail but why can't getopt be extended as is?
Secondly there is a precedent of enforce/enforceEx so go with getoptEx.

@burner
Copy link
Member Author

burner commented Apr 22, 2014

It could be extended, but it would break the current api.
I will change the name to getoptEx

@ghost
Copy link

ghost commented Apr 22, 2014

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.

@burner
Copy link
Member Author

burner commented Apr 22, 2014

int help;
getopt("h|help", &heig)
...

"h|help" might have two meanings

@DmitryOlshansky
Copy link
Member

"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.

@burner
Copy link
Member Author

burner commented Apr 23, 2014

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.

@DmitryOlshansky
Copy link
Member

I don't like this fix.

You don't have to.

It doesn't even fix my example.

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).

@burner
Copy link
Member Author

burner commented Apr 23, 2014

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.

@jcrapuchettes
Copy link
Contributor

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?

@DmitryOlshansky
Copy link
Member

@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?

@burner
Copy link
Member Author

burner commented May 30, 2014

it requires that h|help are not in use. It breaks the semantic of the getopt api.

@DmitryOlshansky
Copy link
Member

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)

@jmdavis
Copy link
Member

jmdavis commented Jun 2, 2014

If the concern is that somehow might already be using "h|help", and that changing getopt to support help info would then break them, then all we have to do is add another option to the config enum which turns the new functionality on. Existing code would then be unaffected.

@burner
Copy link
Member Author

burner commented Jun 3, 2014

I will move the stuff to getopt

@burner
Copy link
Member Author

burner commented Jun 5, 2014

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
Copy link
Member

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 :)

Copy link
Member Author

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.

Copy link
Member

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. ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jcrapuchettes
Copy link
Contributor

Can we get this into 2.066? 👍

@burner
Copy link
Member Author

burner commented Jun 14, 2014

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(
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

some tinkering

alot more

comments

some more

more doc

getoptX cleanup

tuple -> struct

getoptX -> getoptEx

Required

getoptEx is now inline

GetoptRslt -> GetoptResult

more info

some comment fixes
@WalterBright
Copy link
Member

Auto-merge toggled on

@burner
Copy link
Member Author

burner commented Jul 10, 2014

thank you

WalterBright added a commit that referenced this pull request Jul 10, 2014
getoptX Help Messages for getopt
@WalterBright WalterBright merged commit dc97d14 into dlang:master Jul 10, 2014
@jcrapuchettes
Copy link
Contributor

@AndrewEdwards - Would it be possible to get this into the 2.066 release?

@AndrewEdwards
Copy link
Contributor

@jcrapuchettes https://issues.dlang.org/show_bug.cgi?id=13072,
A link to the issue used for cherry-picking is included at the bottom of each beta announcement. A new one will be created for each beta/rc. Post there any bug/regression fix deemed critical/necessary for the current release.

@mihails-strasuns
Copy link

And considering this is neither bug nor regression it should wait for 2.067

@jcrapuchettes
Copy link
Contributor

We have a need for this here at EMSI and having it in the 2.066 release would be a big benefit to us.

@mihails-strasuns
Copy link

Would it help preparing separate 2.066 distribution for internal EMSI usage with this changeset included?

@jcrapuchettes
Copy link
Contributor

We prefer to use stock releases. If this change can't make it into 2.066, we can wait till 2.067.

@mihails-strasuns
Copy link

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.

@jcrapuchettes
Copy link
Contributor

I understand. We currently use a workaround and will plan on continuing to use that till the next release.

@MartinNowak
Copy link
Member

This is actually amazing. Just found out about it now, should make it to the changelog for 2.067.
http://dlang.org/changelog.html

@MartinNowak MartinNowak added this to the 2.067 milestone Mar 3, 2015
@burner burner deleted the getoptx branch October 23, 2015 09:28
@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=16684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.