Coder Social home page Coder Social logo

Comments (2)

BurntSushi avatar BurntSushi commented on June 13, 2024

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.

justinnoah avatar justinnoah commented on June 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.