You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

2 years ago
  1. /*****************************************************************************
  2. *
  3. * demo program - part of CLIPP (command line interfaces for modern C++)
  4. *
  5. * released under MIT license
  6. *
  7. * (c) 2017-2018 André Müller; foss@andremueller-online.de
  8. *
  9. *****************************************************************************/
  10. #include <iostream>
  11. #include <clipp.h>
  12. int main(int argc, char* argv[])
  13. {
  14. using namespace clipp;
  15. using std::cout;
  16. bool a = false, b = false, c = true; //target variables
  17. auto cli = (
  18. option("-a").set(a) % "activates a",
  19. option("-b").set(b) % "activates b",
  20. option("-c", "--noc").set(c,false) % "deactivates c",
  21. option("--hi")([]{cout << "hi!\n";}) % "says hi");
  22. if(parse(argc, argv, cli)) {
  23. cout << std::boolalpha
  24. << "a=" << a << "\nb=" << b << "\nc=" << c << '\n';
  25. } else {
  26. cout << make_man_page(cli, argv[0]) << '\n';
  27. }
  28. // alternative style 1: member functions instead of operators
  29. // auto cli = (
  30. // option("-b").set(b).doc("activates b"),
  31. // option("-c", "--noc").set(c,false).doc("deactivates c"),
  32. // option("--hi").call([]{cout << "hi!\n";}).doc("says hi") );
  33. // alternative style 2: even more operators
  34. // auto cli = (
  35. // option("-b") % "activates b" >> b,
  36. // option("-c", "--noc") % "deactivates c" >> set(c,false),
  37. // option("--hi") % "says hi" >> []{cout << "hi!\n";} );
  38. // auto cli = (
  39. // option("-b") % "activates b" >> b,
  40. // option("-c", "--noc") % "deactivates c" >> set(c,false),
  41. // option("--hi") % "says hi" >> []{cout << "hi!\n";} );
  42. // auto cli = (
  43. // b << option("-b") % "activates b",
  44. // set(c,false) << option("-c", "--noc") % "deactivates c",
  45. // []{cout << "hi!\n";} << option("--hi") % "says hi" );
  46. // auto cli = (
  47. // "activates b" % option("-b") >> b,
  48. // "deactivates c" % option("-c", "--noc") >> set(c,false),
  49. // "says hi" % option("--hi") >> []{cout << "hi!\n";} );
  50. }