Comments (6)
I think I initially had reasons for not doing this but they all seem a bit weak now. I like the idea of doing this automatically.
I personally find negations using +
to be counter-intuitive, but I'm aware that they're used in a number of places, so I'm not against giving people the option to use them if we can find a simple way of doing it. I'll keep this in mind when looking at #2.
from defopt.
an alternative would be negations using the uppercase short opt.
from defopt.
What's the point of the inverted flags? I know they're used in some places, but they just seem confusing to me. Here's an actual example from pip install -h
:
--compile Compile py files to pyc
--no-compile Do not compile py files to pyc
Obviously one of these must be the default, but I have no way of telling. Since one of them is implied by not specifying it, why do we need the flag at all?
Here's another flag for the same command:
--no-clean Don't clean up build directories.
Since there is no corresponding --clean
flag, I know that the default behavior must be to clean up build directories.
from defopt.
with both, the default can be changed anytime (--flag
means True, --no-flag
means False)
and as the later option trumps, you can override stuff in aliases, …
alias ls='ls -l'
$ ls
drwxr-xr-x 1 phil users 314 6. Mär 12:12 bin/
$ ls -x
bin/
from defopt.
I've had a shot at an implementation of this to use as a discussion point. Take a look at 09bdead.
Some points to discuss:
- This only applies to optional arguments; a positional boolean argument is still specified as something accepted by
_parse_bool
. - The help message only shows documentation for the
--name
flag; the--no-name
flag is blank but comes immediately after the other flag so should be clear enough. - This allows for you to have None or some other value as the default, so neither
--name
nor--no-name
are necessarily implied to match the default behavior (if you really want to do that).
from defopt.
This has been implemented and will be in 2.0. Discussion on how to handle short flags can continue in #2 if necessary.
from defopt.
Related Issues (20)
- feature request: better support for options that take multiple arguments and have a default HOT 2
- feature request: support "count" action HOT 2
- Documented strong compatibility guarantees HOT 2
- Add a registry class HOT 4
- When subclassing enum with data mixin, choices are not present on CLI HOT 8
- Consume command line arguments in 2 function calls HOT 10
- Support URLs in docstring
- Reject duplicate options for a single parameter rather than silently dropping one HOT 2
- Any way to indent within tool help text without runtime / linting error? HOT 1
- Add support for datetime.date and datetime.datetime parsers HOT 5
- Argument name suffixes as workaround for name collisions HOT 4
- Should `Optional[Tuple[type1]]` be supported HOT 7
- PyInstaller, Nuitka compatibility? HOT 5
- pin setuptools_scm < 6.4 to support python3.6 HOT 2
- Consume command line arguments in 2 calls - help text has only one call's parameters HOT 17
- Using keyword only dataclass with `defopt.run` gives a docutils warning HOT 1
- py.typed file? HOT 3
- NotImplementedError: <class 'defopt._parse_docstring.<locals>.Visitor'> visiting unknown node type: definition_list HOT 3
- TypeError: can only join an iterable HOT 2
- Feature Request: Make Optional[bool] still act as a flag HOT 1
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 defopt.