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.

57 lines
1.6 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 <string>
  12. #include <clipp.h>
  13. int main(int argc, char* argv[])
  14. {
  15. using namespace clipp;
  16. using std::cout;
  17. bool x = false, y = false, a = false, b = false;
  18. bool g = false, h = false, e = false, f = false;
  19. auto cli = (
  20. ( option("x").set(x) % "sets X", //simple group
  21. option("y").set(y) % "sets Y"
  22. ),
  23. ( option("a").set(a) % "activates A",
  24. option("b").set(b) % "activates B"
  25. ) % "documented group 1:" //docstring after group
  26. ,
  27. "documented group 2:" % ( //docstring before group
  28. option("-g").set(g) % "activates G",
  29. option("-h").set(h) % "activates H"
  30. ),
  31. "activates E or F" % (
  32. option("-e").set(e), //no docstrings inside group
  33. option("-f").set(f)
  34. )
  35. );
  36. if(!parse(argc, argv, cli)) {
  37. cout << make_man_page(cli, argv[0]) << '\n';
  38. }
  39. else {
  40. cout << std::boolalpha
  41. << "x = " << x << '\n'
  42. << "y = " << y << '\n'
  43. << "a = " << a << '\n'
  44. << "b = " << b << '\n'
  45. << "g = " << g << '\n'
  46. << "h = " << h << '\n'
  47. << "e = " << e << '\n'
  48. << "f = " << f << '\n';
  49. }
  50. }