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

Docopt library #4658

Closed
brendanzab opened this issue Jan 28, 2013 · 19 comments
Closed

Docopt library #4658

brendanzab opened this issue Jan 28, 2013 · 19 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@brendanzab
Copy link
Member

This would make creating command line interfaces much easier: http://docopt.org/

@z0w0
Copy link
Contributor

z0w0 commented Feb 5, 2013

I feel like this should be a third party library and not in the std/core library. Considering that all of the implementations are installed using language-based package managers, that seems the norm.

@bstrie
Copy link
Contributor

bstrie commented Apr 29, 2013

I agree with z0w0 that such a thing is beyond the scope of libcore (maybe not libstd). However, this sort of thing relies upon compile-time transformations, which requires a syntax extension, which currently must be defined in the compiler. If nothing else this is a plea for an API for externally-defined syntax extensions.

@bblum
Copy link
Contributor

bblum commented Jul 3, 2013

nominating for far-future; it doesn't look like there would be any backward-compatibility issues or anything.

@graydon
Copy link
Contributor

graydon commented Aug 1, 2013

just a bug, removing milestone/nomination.

@emberian
Copy link
Member

docopt looks awesome! since loadable syntax extensions are coming, this could probably work out really well.

@emberian
Copy link
Member

So I'm marking this E-easy and E-mentor, offering myself as the mentor. I'll post an update once #11151 lands. This isn't trivial, but it shouldn't be too hard, either. It involves parsing the input and generating the correct AST to implement the parsing / structures of the input. We could also add some lightweight typing to docopt.

This is not suitable for a complete beginner.

@emberian
Copy link
Member

Loadable syntax have extended (#11151)

@Kimundi
Copy link
Member

Kimundi commented Jan 17, 2014

I'm still kinda toying around with this, but sadly I don't have much time at the moment.
Now that we have loadable syntax extensions, this can however just be a independent library, so maybe this could be closed now?

@bytbox
Copy link
Contributor

bytbox commented Jan 24, 2014

Is there room for a more-convenient (but less elaborate) alternative to getopts in extra::? I'm often frustrated by how verbose code that uses getopts can get, and I think something similar to go's "flag" package (but based on getopts for consistency) would be nice.

@joseph-norman
Copy link

DocOpt is a fantastic third party library that I've used in Python to great advantage. However like everyone else I believe it should be just that. A third party library. imo it doesn't really belong in libcore.

@dcbishop
Copy link

dcbishop commented Apr 3, 2014

I would love to see this in Rust. Sure it shouldn't be in core but there are other libs included as part of rust, there is 'extern crate getopt' already and I don't really see that being more appropriate.

The main issue is it would probably need a regex library if you follow the Python implementation, otherwise maybe a tokenizer implementation.

@brendanzab
Copy link
Member Author

I think a tokeniser based solution would be more 'rustic'. It would be a difficult port though.

@BurntSushi
Copy link
Member

I am working on a docopt port to Rust since the current one seems dead.

@bjz's instincts were right. This project was an order of magnitude more difficult than I thought it would be. The difficulty wasn't related to Rust in any way, but in interpreting the upstream spec (hint: there isn't one).

My project has the hard parts done: parsing usage patterns, matching argv and storing the relevant values. Now I just need to clean up my code, write tests and come up with a nice public interface, probably by using a macro.

Also, my port implements a proper backtracking search, so patterns like cp FILE... DIR already work. (They don't work with the current Python implementation.)

@brendanzab
Copy link
Member Author

The difficulty wasn't related to Rust in any way, but in interpreting the upstream spec (hint: there isn't one).

They seriously have no grammar specification? o_o

@BurntSushi
Copy link
Member

@bjz They want one: docopt/docopt#20

There are a lot of weird corner cases that aren't specified though. Are flags allowed more than one synonym? If a flag is repeated in one usage pattern, does that mean its value should always be a count/list even in other patterns where it isn't repeated? Things like that. I had to look at how the reference implementation worked to infer such things.

@BurntSushi
Copy link
Member

I have a conforming implementation: https://github.com/BurntSushi/docopt.rs

@emberian
Copy link
Member

emberian commented Aug 1, 2014

@BurntSushi is awesome.

@emberian emberian closed this as completed Aug 1, 2014
@steveklabnik
Copy link
Member

👍

@BurntSushi
Copy link
Member

@cmr ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests