Comments (4)
This seems like a reasonable idea, but I would want to get it right, and there are a few rough cases:
- how to do escaping. For instance I might want the string
Dwayne "The Rock" Johnson
. This should be easily explainable. - how to deal with escaping. eg if the string contains a
]
then the currentre.findall(r"\[default: (.*)\]")
would fail. Of course, this also currently fails if you want a]
in your default, but currenlty it is a bit more obvious that this should fail. Once you add quoting, I think we would need this to work.
Once we figure those out, and add tests and docs, then it sounds great!
from docopt-ng.
Indeed I see the Pandora's box of string quoting.
The way I implemented in #47 cowardly avoid having to deal with it. It works as previously: re.findall(r"\[default: (.*)\]")
but it just adds a check after the match is successful. If it is the case that the match starts and ends with the same quote character (both single or both double) than it strips them and that's it.
This example just works and result in Dwayne "The Rock" Johnson
:
--main-actor=<name> name of the movie's main actor [default: Dwayne "The Rock" Johnson]
This might not be intuitive or elegant but it is easy to use and always has a solution, even for strings that do start and end with quotes:
- enclose it with "the other" quote character
[default: '"The Rock"']
- enclose it with "the same" quote character
[default: ""The Rock""]
However, confusion may arise when users of the library might not expect quoting to be implemented and, expecting "The Rock"
, writes this:
--main-actor-nickname=<name> name of the movie's main actor [default: "The Rock"]
One way around it would be to
- specifically enable this feature when needed:
arguments = docopt(__doc__, quoted_defaults=True)
- document it properly and expect developers using the library to apply extra care when dealing with quotes anyway
from docopt-ng.
As for string containing ]
, because .*
is greedy, it doesn't pose any problem I reckon. The following example already works as expected (resulting in []
) with or without quoting.
--group-enclosure=<pair> open/close grouping characters [default: []]
from docopt-ng.
Related Issues (20)
- Performance penalty: combinatorial explosion in `transform` HOT 3
- Make PEP561 compatible (allow mypy to actually find type hints) HOT 8
- When docopt and docopt-ng are in the same venv, docopt takes precedence HOT 6
- Add @NickCrews to test.pypi.org HOT 1
- docopt-ng fails to parse usage string that worked with docopt HOT 4
- Question: auto formatting & sorting imports HOT 5
- Is it possible to separate options in subsections? HOT 2
- Failing to put two spaces in description sometimes results in very obscure error. HOT 1
- Integrate docopt-dispatch in this project HOT 5
- Claim `docopt` name on pypi (PEP-541) HOT 10
- assert instr.opname.startswith("CALL_") throws on Python 3.11 HOT 5
- TODO: port spellchecker to suggest, rather than fix HOT 1
- DISCUSS: future of docopt-ng HOT 18
- docopt.DocoptLanguageError: unmatched '[' HOT 1
- If there is unused data in the command line, the thrown exception doesn't include the collected and left items HOT 1
- command line parsing is storing some options multiple times HOT 2
- Allow dumping of parse tree, to make it easier to check what docopt will actually parse HOT 1
- Support envvar token HOT 1
- docopt to readthedocs / sphinx docstrings HOT 7
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-ng.