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

Deprecated retired options #358

Merged
merged 11 commits into from
Dec 5, 2019

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented Dec 1, 2019

adds helper functions for retired and deprecated options

Fixes #275

@phlptp
Copy link
Collaborator Author

phlptp commented Dec 1, 2019

TODO

  • add documentation
  • add some comments and explanation to the example
  • verify code coverage
  • rename a few variable
  • verify coverage

@codecov
Copy link

codecov bot commented Dec 1, 2019

Codecov Report

Merging #358 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #358   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          12     12           
  Lines        3353   3396   +43     
=====================================
+ Hits         3353   3396   +43
Impacted Files Coverage Δ
include/CLI/Option.hpp 100% <100%> (ø) ⬆️
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 ba7b29f...c326f73. Read the comment docs.

@phlptp phlptp changed the title [WIP] Deprecated retired options Deprecated retired options Dec 3, 2019
Copy link
Collaborator

@cbachhuber cbachhuber left a comment

Choose a reason for hiding this comment

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

Thank you for this addition! Looks very good already, I only have minor remarks.

examples/retired.cpp Outdated Show resolved Hide resolved
examples/retired.cpp Outdated Show resolved Hide resolved
examples/retired.cpp Outdated Show resolved Hide resolved
examples/retired.cpp Outdated Show resolved Hide resolved
// deprecate an existing option and specify a recommended replacement
CLI::deprecate_option(opt2, "--not_deprecated");

CLI11_PARSE(app, argc, argv);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Many other examples do a std::cout at the end, to show what is going on. Does that make sense here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe something that prints out if the '--not_deprecated` or no options were passed, just so there is always guaranteed to be some output?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good suggestion, I like it!

->type_name("RETIRED")
->expected(0, 1)
->default_str("RETIRED");
Validator cv{[opt2](std::string &) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this object called cv? Could you find a more epressive name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

custom validator, I will rename it

include/CLI/App.hpp Outdated Show resolved Hide resolved
include/CLI/App.hpp Outdated Show resolved Hide resolved
}

/// Helper function to mark an option as deprecated
inline void deprecate_option(App &app, const std::string &option_name, const std::string &replacement = "") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

My IDE complains that this function is never used. Is my IDE wrong? Manually, I also can't find usages and wonder how you get 100% coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought I was using it one of the tests but I will double check that and make sure

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks!

/// Helper function to mark an option as retired
inline void retire_option(App *app, Option *opt) {
App temp;
auto ropt = temp.add_option(opt->get_name(false, true))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need ropt in addition to opt? Consider a more descriptive name for this object

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need to create a temporary psuedo copy of the option before destroying the original, and then copying the copy with the critical info. I will rename it something more descriptive though.

phlptp and others added 3 commits December 3, 2019 11:56
Co-Authored-By: Christoph Bachhuber <cbachhuber89@gmail.com>
Copy link
Collaborator

@cbachhuber cbachhuber left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! 👍

@henryiii
Copy link
Collaborator

henryiii commented Dec 4, 2019

Looks good to me, are you ready to merge?

@phlptp
Copy link
Collaborator Author

phlptp commented Dec 4, 2019

I think it is ready.

@henryiii henryiii merged commit fc0f82a into CLIUtils:master Dec 5, 2019
@henryiii henryiii deleted the deprecated_retired_options branch December 5, 2019 02:16
@henryiii henryiii added this to the v1.9 milestone Dec 31, 2019
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.

Feature request: mark a flag as deprecated or retired
3 participants