Comments (3)
int(options["<x>"])
is what I have in some of my throw-away scripts, and I'm not totally happy with this.
However there is little overhead in using schema. Compare:
- your API:
args = docopt(__doc__, conversions={'<x>': int, '<y>': int})
- docopt with schema:
Int = Or(None, Use(int))
args = Schema({'<x>': Int, '<y>': Int}).validate(docopt(__doc__))
And the more complex your CLI is—the smaller is the relative overhead.
Also, I have never seen a program that takes arbitrary integers—except for calculators—it is always a range or a set, which you can express easily with schema:
schema = Schema({'<x>': And(Use(int), lambda n: n in [2**n for n in range(10)]))
from docopt.
As said on Reddit: I'm almost convinced, yet I still think it's not DRY that way: you have to tell schema which arguments are optional, while docopt already knows about that.
from docopt.
As I said somewhere before—I prefer to err on the side of simplicity. Anyway, thanks for suggestion—more of that is always welcome.
from docopt.
Related Issues (20)
- Is docopt / docopt itself still being maintained? HOT 1
- Please upload a wheel package to pypi HOT 6
- get_docopts.sh fails on M1 Monterey 12.6
- Short options in docopt not returning correct values HOT 1
- [FeatureRequest] Allow hash comments in docstring ? HOT 4
- Make new release HOT 3
- try.docopt.org is offline HOT 1
- Dart port? HOT 1
- Make docopt exceptions public
- How to call "python -m mypackage [options]" HOT 1
- Is there some docopt validator? HOT 1
- Why cannot docopt parse args? HOT 3
- Please share wheel file on pypi HOT 1
- Docopt AssertionError
- Having same issues as #516
- Unix-style vs. Windows-style options HOT 2
- Abandonware status of docopt HOT 7
- Why is the docopt website not served through HTTPS?
- Any good reason not to use GitHub releases? HOT 1
- how to implement number argument? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docopt.