Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using optional args out of order leads to wrong values all around #148

Open
ericonr opened this issue Feb 14, 2022 · 2 comments
Open

Using optional args out of order leads to wrong values all around #148

ericonr opened this issue Feb 14, 2022 · 2 comments
Labels

Comments

@ericonr
Copy link

ericonr commented Feb 14, 2022

#include "docopt.h"
#include <iostream>

static const char usage[] =
R"(Usage:
    order [-t <vt> -C <vc>]

Options:
-t <vt>  T val
-C <vc>  C val
)";

int main(int argc, char *argv[])
{
    std::map<std::string, docopt::value> args = docopt::docopt(usage, {argv+1, argv+argc}, true);

    for(auto const& arg : args) {
        std::cout << arg.first << ": " << arg.second << std::endl;
    }
}

In same order as the help string (correct):

./order -t 0 -C 1
-C: true
-t: true
<vc>: "1"
<vt>: "0"

In opposite order (wrong):

./order -C 0 -t 1
-C: true
-t: true
<vc>: "1"
<vt>: "0"

Only the first one (correct):

./order -t 0
-C: false
-t: true
<vc>: null
<vt>: "0"

Only the second one (wrong):

./order -C 0
-C: true
-t: false
<vc>: null
<vt>: "0"
ericonr added a commit to lnls-dig/uhal that referenced this issue Apr 20, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

Needs to be updated to argparse 2.3 (per [3]) to actually compile.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
[3] mesonbuild/wrapdb#393
@jaredgrubb
Copy link
Member

I think this is mostly behaving correctly -- as I don't think the original docopt in Python does this as well.

This would probably be pretty hard to add on. What is the use-case where this would be useful?

ericonr added a commit to lnls-dig/uhal that referenced this issue May 20, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
ericonr added a commit to lnls-dig/uhal that referenced this issue Jun 3, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
@ericonr
Copy link
Author

ericonr commented Jun 11, 2022

I'm not sure I understand your comment? As far as I can see it isn't a new feature, but a bug which has the parser all confused and putting the wrong things in the return map.

ericonr added a commit to lnls-dig/uhal that referenced this issue Aug 19, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
ericonr added a commit to lnls-dig/uhal that referenced this issue Sep 9, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
ericonr added a commit to lnls-dig/uhal that referenced this issue Sep 9, 2022
Doesn't suffer from bugs found in docopt (at least [1] and [2]), has
more active development and a better API.

[1] docopt/docopt.cpp#147
[2] docopt/docopt.cpp#148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants