proxygen
ProgramOptionsTestHelper.cpp File Reference
#include <iostream>
#include <glog/logging.h>
#include <folly/Conv.h>
#include <folly/experimental/ProgramOptions.h>

Go to the source code of this file.

Functions

 DEFINE_bool (flag_bool_true, true,"Bool with true default value")
 
 DEFINE_bool (flag_bool_false, false,"Bool with false default value")
 
 DEFINE_int32 (flag_int, 42,"Integer flag")
 
 DEFINE_string (flag_string,"foo","String flag")
 
int main (int argc, char *argv[])
 

Function Documentation

DEFINE_bool ( flag_bool_true  ,
true  ,
"Bool with true default value  
)
DEFINE_bool ( flag_bool_false  ,
false  ,
"Bool with false default value  
)
DEFINE_int32 ( flag_int  ,
42  ,
"Integer flag  
)
DEFINE_string ( flag_string  ,
"foo"  ,
"String flag  
)
int main ( int  argc,
char *  argv[] 
)

Definition at line 39 of file ProgramOptionsTestHelper.cpp.

References folly::getGFlags(), folly::GFLAGS, folly::GNU, and folly::parseNestedCommandLine().

39  {
40  po::options_description desc;
41  auto styleEnv = getenv("PROGRAM_OPTIONS_TEST_STYLE");
42 
43  CHECK(styleEnv) << "PROGRAM_OPTIONS_TEST_STYLE is required";
44  bool gnuStyle = !strcmp(styleEnv, "GNU");
45  CHECK(gnuStyle || !strcmp(styleEnv, "GFLAGS"))
46  << "Invalid value for PROGRAM_OPTIONS_TEST_STYLE";
47 
48  // clang-format off
49  desc.add(getGFlags(
52  desc.add_options()
53  ("help,h", "help");
54  // clang-format on
55 
56  po::variables_map vm;
57  auto result = folly::parseNestedCommandLine(argc, argv, desc);
58  po::store(result.options, vm);
59  po::notify(vm);
60 
61  if (vm.count("help")) {
62  std::cout << desc;
63  return 1;
64  }
65 
66  print<bool>(vm, gnuStyle ? "flag-bool-true" : "flag_bool_true");
67  print<bool>(vm, gnuStyle ? "flag-bool-false" : "flag_bool_false");
68  print<int32_t>(vm, gnuStyle ? "flag-int" : "flag_int");
69  print<std::string>(vm, gnuStyle ? "flag-string" : "flag_string");
70 
71  if (result.command) {
72  printf("command %s\n", result.command->c_str());
73  }
74 
75  for (auto& arg : result.rest) {
76  printf("arg %s\n", arg.c_str());
77  }
78 
79  return 0;
80 }
NestedCommandLineParseResult parseNestedCommandLine(int argc, const char *const argv[], const po::options_description &desc)
char ** argv
po::options_description getGFlags(ProgramOptionsStyle style)