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.

45 lines
1.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 <string>
  12. #include <vector>
  13. #include <clipp.h>
  14. int main(int argc, char* argv[])
  15. {
  16. using namespace clipp;
  17. using std::string;
  18. using std::cout;
  19. int n = 1;
  20. bool errStop = false;
  21. string exe;
  22. std::vector<string> args;
  23. auto cli = (
  24. option("-n", "--repeat") & value("times", n) % "execute multiple times",
  25. option("-s", "--stop-on-error").set(errStop) % "stop on error",
  26. value("executable", exe) % "client program",
  27. option("--") & values("args", args) % "client arguments"
  28. );
  29. if(!parse(argc, argv, cli)) {
  30. cout << make_man_page(cli, argv[0]) << '\n';
  31. }
  32. cout << "call: " << exe;
  33. for(const auto& a : args) cout << ' ' << a;
  34. cout << '\n';
  35. cout << n << " times\n";
  36. if(errStop) cout << "execution will be stopped on any error\n";
  37. }