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

Bugfix for blank pattern among other subcommands #29

Merged
merged 2 commits into from Jun 23, 2012

Conversation

Met48
Copy link
Contributor

@Met48 Met48 commented Jun 21, 2012

See test_bug() for an example of the issue.

See test_bug() for an example of the issue.
@keleshev
Copy link
Member

Isn't it a bit of a hack to manipulate printable usage, instead of how it is parsed? I was attempting to change parsing to fix this.

Otherwise we're short on 1 bug—that's great. I will pull when I get home.

@Met48
Copy link
Contributor Author

Met48 commented Jun 22, 2012

I don't think so, as the issue results from how an Either being parsed will ignore empty options. This only prevents weird usage strings like this:

usage: prog (a|b|)

Fixing the parsing allows this as well.

@keleshev
Copy link
Member

Maybe I don't understand you 100%, but why not allow (a|b|) to be equivalent to (a|b|()) and thus to [a|b] (this maybe gives some opportunity to refactor (eliminate?) Optional). I would consider changing how Either is parsed.

@Met48
Copy link
Contributor Author

Met48 commented Jun 22, 2012

I think refactoring away Optional can be done easily actually - just update line 379 to create a Required containing an Either node for each result of the parse_expr (with an empty case as well), then remove the other few references.

My only concerns with a format like (a|b|) are that it is visually confusing to the user and could also indicate a programmer error. After all, [a|b] is equivalent and is by far a clearer way of expressing the intent. Another problematic expression is a | at the start / end of a line, as in Usage: prog add <name> |. This could occur while the programmer is refactoring the usage message. I think the best solution here would be to raise a parsing error if a user-created Either has an empty case, rather than have them surprised when it later does or doesn't accept the empty case.

As a side note, I thought of a much better approach with more consistent behaviour than this commit, so I'll be updating this pull request later today.

One test updated due to new formal usage.
@Met48
Copy link
Contributor Author

Met48 commented Jun 22, 2012

@halst I've updated the pull request to a lot more concise a solution. It also no longer alters the (undefined) behaviour with leading or trailing | characters. All tests pass except one which explicitly checks the formal usage and has since been updated.

@keleshev
Copy link
Member

This one is good. I will say it's an elegant hack that fixes serious bug—so I pull this.

keleshev added a commit that referenced this pull request Jun 23, 2012
Bugfix for blank pattern among other subcommands
@keleshev keleshev merged commit 171f231 into docopt:bugfix Jun 23, 2012
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.

None yet

3 participants