Skip to content

fix: commenting of descriptions with embedded newlines - #592

Merged
henryiii merged 2 commits into
CLIUtils:masterfrom
paddy-hack:master
Jun 28, 2021
Merged

henryiii merged 2 commits into
CLIUtils:masterfrom
paddy-hack:master

Conversation

@paddy-hack

Copy link
Copy Markdown
Contributor

Anything written in write_descriptions-guarded code blocks should assume that whatever text is provided by library users may contain embedded newlines. This fixes the places where this wasn't done.

@paddy-hack

Copy link
Copy Markdown
Contributor Author

FYI, the failed appveyor job appears to have been caused by a failed download of a build requisite, catch.hpp. I have no trouble downloading it manually. The sha256sum of my download matches what the build expects ...

@henryiii henryiii closed this Jun 15, 2021
@henryiii henryiii reopened this Jun 15, 2021
@henryiii

Copy link
Copy Markdown
Collaborator

Could you add a little test for this? Otherwise, I will, but it will likely get merged faster if you add one. There's a file with config tests in it.

@codecov

codecov Bot commented Jun 15, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #592 (972d04e) into master (4af78be) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 972d04e differs from pull request most recent head 8462249. Consider uploading reports for the commit 8462249 to get more accurate results
Impacted file tree graph

@@            Coverage Diff            @@
##            master      #592   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines         3764      3764           
=========================================
  Hits          3764      3764           
Impacted Files Coverage Δ
include/CLI/Config.hpp 100.00% <100.00%> (ø)

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 aa31576...8462249. Read the comment docs.

@paddy-hack

Copy link
Copy Markdown
Contributor Author

Although I'm pretty sure I could implement a few tests, I am pressed for time and wouldn't know where to start to begin with. I guess things will move along faster if you add the tests.

@paddy-hack

Copy link
Copy Markdown
Contributor Author

Just noticed the merge conflict. Appears to have been introduced due to #593 submitted by me 😮 Should be straightforward to fix.

@henryiii

Copy link
Copy Markdown
Collaborator

Can you paste an example config file to use in test, possibly? I don't mind making the test, but having an example file will help.

@henryiii henryiii added this to the v2.0 milestone Jun 24, 2021
@paddy-hack

Copy link
Copy Markdown
Contributor Author

I had opportunity to fiddle with my application's command line so put some time aside to add tests for my changes. Looking over a few existing tests was enough to get me up to speed 😅

Adding tests, I discovered that only the first hunk of my merge request is strictly needed. It will address all multi-line descriptions. The other two hunks address multi-line group names and multi-line subcommands. The latter would be extremely cumbersome to use on the command-line. The former, multi-line group names, is very unlikely.

This made me wonder what to do. Currently, one is able to set multi-line group names and subcommands. If one does, config_to_str() produces content that is not usable as a configuration file. Should I just leave the fix_newlines() in or would it be better to add validation that prevents group names and subcommands from being multi-line strings?

@paddy-hack

Copy link
Copy Markdown
Contributor Author

Oops! Just noticed that subcommands already check for embedded newlines and throw when they find one. That leaves group names. I'm inclined to add validation for those rather than allow embedded newlines. What do you think?

@phlptp

phlptp commented Jun 28, 2021

Copy link
Copy Markdown
Collaborator

My inclination would be to put the same check on group names as is on subcommands.

@paddy-hack

Copy link
Copy Markdown
Contributor Author

A quick search shows that App::group() and OptionBase::group() need to add validation. Short of more or less copy-and-pasting the validation from App::add_subcommand(), any suggestions to implement this without code duplication?

@paddy-hack

paddy-hack commented Jun 28, 2021 •

Copy link
Copy Markdown
Contributor Author

Hmm, group names in the tests use spaces. These aren't allowed in subcommands so that needs a bit of extra tinkering ...
Working on it, will probably end up using copy-and-paste and leave it for others to refactor away the duplication 😉

This adds tests for the application's description as well as option
groups and subcommands.

See CLIUtils#592.
@paddy-hack

Copy link
Copy Markdown
Contributor Author

I'll do the group name validation in a separate PR.

@phlptp

phlptp commented Jun 28, 2021

Copy link
Copy Markdown
Collaborator

we had some discussion earlier about relaxing the restrictions on subcommand names, to allow other characters, basically everything but =:!{} and newlines and not starting with / or -. So I am guessing we can merge the checks at that point.

@paddy-hack

Copy link
Copy Markdown
Contributor Author

OK. Then I won't be submitting a group name validation PR. Saves me some work 😉

@henryiii

Copy link
Copy Markdown
Collaborator

Fantastic, thank you!

@henryiii
henryiii merged commit 2255619 into CLIUtils:master Jun 28, 2021
@github-actions github-actions Bot added needs changelog Hasn't been added to the changelog yet needs README Needs to be mentioned in the README labels Jun 28, 2021
@henryiii henryiii removed needs README Needs to be mentioned in the README needs changelog Hasn't been added to the changelog yet labels Jul 1, 2021
@phlptp phlptp mentioned this pull request Jul 21, 2021
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