Skip to content

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
@eseiler eseiler force-pushed the misc/is_option_set branch from 13e5d42 to 76357e3 Compare February 5, 2024 18:12
@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
@codecov
Copy link

codecov bot commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.75%. Comparing base (d3b3a7b) to head (6ea2963).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   94.62%   94.75%   +0.12%     
==========================================
  Files          18       19       +1     
  Lines        1730     1772      +42     
  Branches       46       47       +1     
==========================================
+ Hits         1637     1679      +42     
  Misses         93       93              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eseiler eseiler force-pushed the misc/is_option_set branch from 76357e3 to 1e9e8a4 Compare February 7, 2024 15:08
@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?)

@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.

@eseiler eseiler force-pushed the misc/is_option_set branch from 1e9e8a4 to e58a7f4 Compare March 13, 2024 14:28
@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 force-pushed the misc/is_option_set branch from 1426353 to 13800ef Compare March 13, 2024 15:53
@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 force-pushed the misc/is_option_set branch from 13800ef to c61c23b Compare March 13, 2024 15:55
@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 force-pushed the misc/is_option_set branch from c745213 to ee41f28 Compare April 9, 2024 10:21
@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
@eseiler eseiler force-pushed the misc/is_option_set branch from a11439e to c1d0aea Compare April 9, 2024 11:31
@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
@eseiler eseiler force-pushed the misc/is_option_set branch from c1d0aea to 85b7f75 Compare April 2, 2025 16:02
@eseiler eseiler removed the request for review from smehringer April 2, 2025 16:02
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Apr 2, 2025
@seqan-actions
Copy link
Member

Documentation preview available at https://docs.seqan.de/preview/seqan/sharg-parser/226

@seqan seqan deleted a comment from vercel bot Apr 2, 2025
EXPECT_THROW(parser.is_option_set("foo"), sharg::design_error);

EXPECT_NO_THROW(parser.parse());
EXPECT_EQ(positional_options.size(), 2u);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is not given, the following 2 lines might be invalid accesses.

Suggested change
EXPECT_EQ(positional_options.size(), 2u);
ASSERT_EQ(positional_options.size(), 2u);

Copy link
Member Author

Choose a reason for hiding this comment

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

Went for EXPECT_EQ(positional_options, (std::vector<std::string>{"--loo", "--bar"}));

@eseiler eseiler force-pushed the misc/is_option_set branch from 85b7f75 to d403d0d Compare April 3, 2025 12:53
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Apr 3, 2025
@eseiler eseiler force-pushed the misc/is_option_set branch from d403d0d to 6ea2963 Compare April 3, 2025 12:54
@eseiler eseiler requested a review from SGSSGene April 3, 2025 12:54
@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Apr 3, 2025
@eseiler eseiler enabled auto-merge April 3, 2025 13:18
@eseiler eseiler merged commit 99b7441 into seqan:main Apr 3, 2025
36 checks passed
@eseiler eseiler deleted the misc/is_option_set branch April 3, 2025 13:37
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.

4 participants