Skip to content

cmdlinet: add value_opt methods #8525

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

Merged
merged 1 commit into from
Dec 10, 2024
Merged

cmdlinet: add value_opt methods #8525

merged 1 commit into from
Dec 10, 2024

Conversation

kroening
Copy link
Member

@kroening kroening commented Dec 6, 2024

This adds an alternative to cmdlinet::get_value, which returns std::optional, as opposed to defaulting to an empty string when the option isn't set.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

This adds an alternative to cmdlinet::get_value, which returns
std::optional, as opposed to defaulting to an empty string when the option
isn't set.
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.85%. Comparing base (7eef276) to head (3c9d699).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/goto-cc/armcc_mode.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8525      +/-   ##
===========================================
+ Coverage    78.58%   78.85%   +0.26%     
===========================================
  Files         1728     1728              
  Lines       199522   198844     -678     
  Branches     18374    18379       +5     
===========================================
+ Hits        156792   156795       +3     
+ Misses       42730    42049     -681     

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

@tautschnig
Copy link
Collaborator

I had the same thought when seeing your hw-cbmc PR...

Comment on lines +79 to +81
std::optional<std::string> value_opt(char option) const;
std::optional<std::string> value_opt(const char *option) const;

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about changing this API to become value_or? So that it would be used like this: cmdline.value_or("log", "-")?

Copy link
Member Author

Choose a reason for hiding this comment

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

Might be confusing given that it is the same method name as std::optional::value_or. Right now what you do is only a little bit longer: cmdline.value_opt("log").value_or("-").

Copy link
Member Author

Choose a reason for hiding this comment

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

We could consider operator()? Then it would be cmdline("log").value_or("-")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps value_or isn't the best name to choose, but it still seems like a nuisance when the only thing we really want is value_opt immediately followed by value_or.

Copy link
Member Author

@kroening kroening Dec 9, 2024

Choose a reason for hiding this comment

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

There is some (very modest) benefit in doing

auto foo_opt = cmdline.value_opt("foo");
if(foo_opt) ....  foo_opt.value()

The benefit is that you avoid the double lookup in the argument map that you'd do with cmdline.isset("foo") followed by cmdline.get_value("foo"). But of course not measurable.

@kroening kroening marked this pull request as ready for review December 7, 2024 14:21
@tautschnig tautschnig merged commit e186314 into develop Dec 10, 2024
41 checks passed
@tautschnig tautschnig deleted the cmdline-value_opt branch December 10, 2024 10:22
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.

2 participants