Skip to content

Support user defined delimiter when parsing list - #209

Merged
henryiii merged 1 commit into
CLIUtils:masterfrom
rafiw:master
Feb 6, 2019
Merged

henryiii merged 1 commit into
CLIUtils:masterfrom
rafiw:master

Conversation

@rafiw

@rafiw rafiw commented Jan 31, 2019

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Jan 31, 2019

Copy link
Copy Markdown

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

codecov Bot commented Jan 31, 2019 •

Copy link
Copy Markdown

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

henryiii commented Jan 31, 2019 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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

Comment thread tests/AppTest.cpp Resolved
@henryiii

henryiii commented Feb 1, 2019

Copy link
Copy Markdown
Collaborator

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

rafiw commented Feb 1, 2019

Copy link
Copy Markdown
Contributor Author

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

rafiw commented Feb 5, 2019 •

Copy link
Copy Markdown
Contributor Author

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

@henryiii

henryiii commented Feb 5, 2019

Copy link
Copy Markdown
Collaborator

Okay, I'll rerun the formatter soon.

@henryiii

henryiii commented Feb 5, 2019

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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