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

[FIX] is_option_set: match both long and short ids #226

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eseiler
Copy link
Member

@eseiler eseiler commented Feb 5, 2024

To-do

  • Decide whether to merge
  • Cleanup
  • Try to handle short/long IDs better

Problem

sharg::parser parser{"test_parser", 5, argv, sharg::update_notifications::off};
parser.add_option(option_value, sharg::config{.short_id = 'b', .long_id = "bar"});
parser.add_option(option_value, sharg::config{.short_id = 'l', .long_id = "loo"});
parser.add_option(option_value, sharg::config{.short_id = 'f', .long_id = "foobar"});

When calling ./parser_test -b blah:

parser.is_option_set('-b'); // True
parser.is_option_set("--bar"); // False

This is quite unintuitive and has already caused me trouble.
A workaround is of course

parser.is_option_set('-b') || parser.is_option_set("--bar");

But this relies on the user to get the short/long ID pairing correct.

Solution
Store short/long ID as a pair. When calling is_option_set, we can search for both short and long ID.

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Feb 5, 2024
Copy link

vercel bot commented Feb 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
sharg-parser ✅ Ready (Inspect) Visit Preview Apr 9, 2024 11:32am

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Feb 5, 2024
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.27%. Comparing base (39f65a4) to head (c1d0aea).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   95.10%   95.27%   +0.17%     
==========================================
  Files          18       19       +1     
  Lines        1735     1777      +42     
==========================================
+ Hits         1650     1693      +43     
+ Misses         85       84       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Feb 7, 2024
Copy link
Member

@smehringer smehringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm in favour of this change, even if its an API break (right?)

include/sharg/detail/format_parse.hpp Outdated Show resolved Hide resolved
include/sharg/detail/format_parse.hpp Show resolved Hide resolved
@eseiler
Copy link
Member Author

eseiler commented Feb 29, 2024

So I'm in favour of this change, even if its an API break (right?)

Shouldn't break API as all the ID handling is internal. It does change the API in the sense that the behavior is fixed :D

@smehringer
Copy link
Member

So I'm in favour of this change, even if its an API break (right?)

Shouldn't break API as all the ID handling is internal. It does change the API in the sense that the behavior is fixed :D

Yeah I guess :) I try to think about cases where people deliberately distinguish between short and long id.. but I can't find an actual use case.

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Mar 13, 2024
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Mar 13, 2024
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Mar 13, 2024
@seqan-actions seqan-actions added the lint [INTERNAL] signals that clang-format ran label Mar 13, 2024
@seqan-actions seqan-actions removed the lint [INTERNAL] signals that clang-format ran label Mar 13, 2024
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Mar 13, 2024
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Mar 13, 2024
@eseiler eseiler marked this pull request as ready for review April 9, 2024 10:21
@seqan-actions seqan-actions added the lint [INTERNAL] signals that clang-format ran label Apr 9, 2024
@seqan-actions seqan-actions removed the lint [INTERNAL] signals that clang-format ran label Apr 9, 2024
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Apr 9, 2024
@eseiler eseiler requested a review from smehringer April 9, 2024 11:48
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