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

Support user defined delimiter when parsing list #209

Merged
merged 1 commit into from
Feb 6, 2019

Conversation

rafiw
Copy link
Contributor

@rafiw rafiw commented Jan 31, 2019

Currently user can only parse list with spaces
E.g app -o 1 2 3
now use can define his own one char delimiter e.g comma

@codecov
Copy link

codecov bot commented Jan 31, 2019

Codecov Report

Merging #209 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #209   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        1932   1933    +1     
=====================================
+ Hits         1932   1933    +1
Impacted Files Coverage Δ
include/CLI/App.hpp 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cd04e3...5228390. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 31, 2019

Codecov Report

Merging #209 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #209   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        1960   1964    +4     
=====================================
+ Hits         1960   1964    +4
Impacted Files Coverage Δ
include/CLI/App.hpp 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4910df...434a247. Read the comment docs.

@henryiii
Copy link
Collaborator

henryiii commented Jan 31, 2019

Please add a few tests, including at least the following cases:

-v 1 2
-v 1,2
-v 1,2,
-v 1, 2
-v "1,2"
-v "1, 2 "

I believe space will always be a separator, since this is what gets passed to CLI11 from argc, argv.

@henryiii
Copy link
Collaborator

I can fix the style pretty trivially if needed. Is there a version with defaults to add too?

tests/AppTest.cpp Outdated Show resolved Hide resolved
@henryiii
Copy link
Collaborator

henryiii commented Feb 1, 2019

This should be added in the

Option *add_option(std::string option_name,
                       std::vector<T> &variable, ///< The variable vector to set
                       std::string description,
                       bool defaulted)

one too, right below, and matching tests copied and pasted in.

@rafiw
Copy link
Contributor Author

rafiw commented Feb 1, 2019

i will update next week

@rafiw rafiw force-pushed the master branch 4 times, most recently from a214831 to 29ed0ae Compare February 5, 2019 14:34
@rafiw
Copy link
Contributor Author

rafiw commented Feb 5, 2019

@henryiii there are some style issues not related to my changes, besides that i think it's ok

@henryiii
Copy link
Collaborator

henryiii commented Feb 5, 2019

Okay, I'll rerun the formatter soon.

@henryiii
Copy link
Collaborator

henryiii commented Feb 5, 2019

Looks like the 5.0.1 version of clang-format is a bit finicky too. I'll play with cleanup tomorrow, and will probably add a couple of clang-format-off directives (or switch to a docker clang-format on Travis and use unibeatify's version).

@henryiii henryiii force-pushed the master branch 2 times, most recently from f659f88 to 434a247 Compare February 6, 2019 09:24
This commit allows parsing any char separated list given by the user.
E.g app -a 1,2,3
std::vector<int> params;
app.add_option("-a", params, "Parse the params", ',');

Signed-off-by: Rafi Wiener <rafiw@mellanox.com>

add tests for delimiter parsing

Signed-off-by: Rafi Wiener <rafiw@mellanox.com>

Fixing style, adding docker version of clang-format
@henryiii henryiii merged commit 048f968 into CLIUtils:master Feb 6, 2019
@henryiii henryiii added this to the v1.8 milestone Feb 9, 2019
@henryiii
Copy link
Collaborator

By the way, I believe the API will change a bit with #240: Instead of an extra argument in add_option, you would do it like this now:

add_option("--thing", vector)->delimiter(',');

As a bonus, the delimiter is now supported by validators and more.

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 this pull request may close these issues.

3 participants