Comments (2)
This is actually working as expected. The problem here is that the failure mode is terrible and that should be fixed (I've changed the title of your issue to reflect that).
The problem is how Docopt things are mapped to struct fields. It's documented, but it's buried in the README
:
-g => flag_g
--group => flag_group
--group <arg> => flag_group
FILE => arg_FILE
<file> => arg_file
build => cmd_build
So in your case, you'd want flag_port
instead of arg_port
. Indeed, swapping these makes your example work just fine (after swapping the rest too). The arg_
prefix is reserved for positional arguments.
Finally, if you change your usage string to use alternations, then you can get your originally desired behavior of catching the case where neither -4
or -6
are specified:
Usage: rtracker ((-4 [--port=<port> --ip=<ip>]) | (-6 [--port6=<port6> --ip6=<ip6>]))
rtracker (--help)
Although, it would be understandable to continue with what you're doing and handle this case explicitly, because the error message for running your command without a -4
or a -6
is simply "Invalid arguments. Here's the usage again:" which isn't terribly helpful. (Basically, Docopt is saying that it can't find a match, but it doesn't know how to say why it can't find a match.)
from docopt.rs.
@BurntSushi I read the readme many times, I can't believe I missed that. Thank you for pointing out that I needed flag_ rather than arg_. Your suggested usage string, however, does not allow for both -4 and -6 to be used simultaneously. 0.6.38 isn't building currently, so I have not tested the struct parameter prefix changes, but I believe that will be the change I need.
from docopt.rs.
Related Issues (20)
- confusing failure mode when usage and option sections are inconsistent HOT 2
- Panic on duplicates in the options section
- argument name with `_` underscore is misaligned to `-` hyphen HOT 1
- Could not compile by docopt_macros error at macro.rs line 187 HOT 1
- Silent breaking change in docopt 0.8.2 HOT 1
- Linking error during compilation HOT 1
- Strange behavior if subcommand starts with program name
- When repeated short and long =value flags are aliases, only one is deserialised HOT 2
- trouble with argument lists split over multiple lines HOT 1
- Allow Overlapping Option and Usage Flags for Documentation
- 1.1.0 Does not compile HOT 5
- Would `docopt_macros` still require nightly? HOT 1
- -h in priority
- Optional argument parsed as None instead of Some(_) if using '_' in option name
- Huge amount of memory used and very slow when parsing many arguments HOT 2
- get_vec and the borrow checker play badly together HOT 1
- Hidden undocumented options? HOT 1
- Positional arguments are misparsed as --required arguments HOT 4
- [Issue] Optional arguments in final array HOT 1
- Does docopt-style API scale to the complex use-cases? HOT 2
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.rs.