Skip to content

Commit

Permalink
Gate GFlag usage in ProgramOptions behind availability
Browse files Browse the repository at this point in the history
Reviewed By: yfeldblum

Differential Revision: D62261372

fbshipit-source-id: 86bef57db3fe62332fccad926a6e0e19fd82273c
  • Loading branch information
praihan authored and facebook-github-bot committed Sep 10, 2024
1 parent 110fd8f commit 9d06773
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions folly/cli/NestedCommandLineApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ class NestedCommandLineApp {
std::string programHelpFooter = std::string(),
InitFunction initFunction = InitFunction());

#if FOLLY_HAVE_LIBGFLAGS && __has_include(<gflags/gflags.h>)
/**
* Add GFlags to the list of supported options with the given style.
*/
void addGFlags(ProgramOptionsStyle style = ProgramOptionsStyle::GNU) {
globalOptions_.add(getGFlags(style));
}
#endif

/**
* Return the global options object, so you can add options.
Expand Down
2 changes: 2 additions & 0 deletions folly/cli/ProgramOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace po = ::boost::program_options;

namespace folly {

#if FOLLY_HAVE_LIBGFLAGS && __has_include(<gflags/gflags.h>)
namespace {

// Information about one GFlag. Handled via shared_ptr, as, in the case
Expand Down Expand Up @@ -285,6 +286,7 @@ po::options_description getGFlags(ProgramOptionsStyle style) {

return desc;
}
#endif

namespace {

Expand Down
2 changes: 2 additions & 0 deletions folly/cli/ProgramOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace folly {

#if FOLLY_HAVE_LIBGFLAGS && __has_include(<gflags/gflags.h>)
enum class ProgramOptionsStyle {
GFLAGS,
GNU,
Expand Down Expand Up @@ -55,6 +56,7 @@ enum class ProgramOptionsStyle {
// and "--flying_pigs=false" are not allowed, to prevent ambiguity.
boost::program_options::options_description getGFlags(
ProgramOptionsStyle style = ProgramOptionsStyle::GNU);
#endif

// Helper when parsing nested command lines:
//
Expand Down

0 comments on commit 9d06773

Please sign in to comment.