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.

44 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::cout;
  18. std::vector<std::string> files;
  19. std::string expr;
  20. bool ifany = false, ifall = false;
  21. auto cli = (
  22. values("file", files) % "input filenames",
  23. (required("-s") & value("expr", expr)) % "string to look for",
  24. option("any").set(ifany) % "report as soon as any matches" |
  25. option("all").set(ifall) % "report only if all match"
  26. );
  27. if(parse(argc, argv, cli)) {
  28. cout << "find '" << expr << "' in files: ";
  29. for(const auto& f : files) { cout << "'" << f << "' "; } cout << '\n';
  30. if(ifany) cout << "using 'any' mode\n";
  31. if(ifall) cout << "using 'all' mode\n";
  32. }
  33. else {
  34. cout << make_man_page(cli, argv[0]) << '\n';
  35. }
  36. }