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

Quoted arguments with spaces are split up #218

Closed
Overv opened this issue Feb 7, 2019 · 7 comments · Fixed by #221
Closed

Quoted arguments with spaces are split up #218

Overv opened this issue Feb 7, 2019 · 7 comments · Fixed by #221

Comments

@Overv
Copy link

Overv commented Feb 7, 2019

Given the following program:

#include <CLI/CLI.hpp>

int main(int argc, char** argv) {
    CLI::App app("foo");

    std::vector<std::string> bar;
    app.add_option("bar", bar, "bar")->required();

    CLI11_PARSE(app, argc, argv);

    for (const auto& entry : bar) {
        std::cout << entry << std::endl;
    }

    return 0;
}

I would expect the output to be like this:

$ ./program this is a test
this
is
a
test
$ ./program "this is a" test
this is a
test

However, the second command instead prints the words separately just like the first command. This seems like a bug caused by #209.

@henryiii
Copy link
Collaborator

henryiii commented Feb 7, 2019

Should be an easy fix. The default should not be ' ', and instead should be "empty" or null, and then ignored if so.

@henryiii
Copy link
Collaborator

henryiii commented Feb 7, 2019

@rafiw, do you think you could change the default char '\0', then skip the loop breaking up the string if that's the case? Otherwise I can do it in a couple of days. PS: I recommend using a branch rather than master of your fork if you make a PR. It gives me an odd feeling force-pushing to a master, even if it is a fork.

@rafiw
Copy link
Contributor

rafiw commented Feb 7, 2019

@henryiii yes master was me been lazy editing the file from the github site.
i will push a PR soon

@henryiii
Copy link
Collaborator

henryiii commented Feb 7, 2019

@rafiw Thanks!

@rafiw
Copy link
Contributor

rafiw commented Feb 7, 2019

i changed a bit the code now i get the following when using ',' as a delimiter

./a.out "this is" a,test "3 3" 4,4,4,4
this is
a
test
3 3
4
4
4
4
./a.out "this is" a,test 3 3 4,4,4,4
this is
a
test
3
3
4
4
4
4
./a.out "this is a,test 3 3 4,4,4,4"
this is a
test 3 3 4
4
4
4
// when specifying no delimiter
./a.out "this is" a,test "3 3" 4,4,4,4
this is
a,test
3 3
4,4,4,4
./a.out this is a test
this
is
a
test
./a.out "this is a" test
this is a
test

@henryiii ok?

@Overv
Copy link
Author

Overv commented Feb 7, 2019

@rafiw Thanks for the quick followup, that looks good to me at least 👍

@henryiii
Copy link
Collaborator

henryiii commented Feb 7, 2019

@rafiw I like it! Feel free to add that little prog as an example, those can get tested too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants