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.

73 lines
2.4 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. using std::string;
  19. enum class mode {make, find, help};
  20. mode selected = mode::help;
  21. std::vector<string> input;
  22. string dict, out;
  23. bool split = false, progr = false;
  24. auto makeMode = (
  25. command("make").set(selected,mode::make),
  26. value("wordfile", input),
  27. required("-dict") & value("dictionary", dict),
  28. option("--progress", "-p").set(progr) % "show progress" );
  29. auto findMode = (
  30. command("find").set(selected,mode::find),
  31. values("infile", input),
  32. required("-dict") & value("dictionary", dict),
  33. (option("-o", "--output") & value("outfile", out)) % "write to file instead of stdout",
  34. ( option("-split" ).set(split,true) |
  35. option("-nosplit").set(split,false) ) % "(do not) split output" );
  36. auto cli = (
  37. (makeMode | findMode | command("help").set(selected,mode::help) ),
  38. option("-v", "--version").call([]{cout << "version 1.0\n\n"; }) % "show version" );
  39. string execname = argv[0];
  40. if(parse(argc, argv, cli)) {
  41. switch(selected) {
  42. case mode::make:
  43. cout << "make new dictionary " << dict << " from wordfile(s) ";
  44. for(const auto& s : input) { cout << s << ' '; } cout << '\n';
  45. break;
  46. case mode::find:
  47. cout << "find words from dictionary " << dict << " in files ";
  48. for(const auto& s : input) { cout << s << ' '; } cout << '\n';
  49. cout << "output: ";
  50. if(split) cout << "splitted ";
  51. cout << "to ";
  52. if(!out.empty()) cout << "file " << out; else cout << "stdin";
  53. cout << '\n';
  54. if(progr) cout << "Progres: [ ] 0%\n";
  55. break;
  56. case mode::help:
  57. cout << make_man_page(cli, execname) << '\n';
  58. break;
  59. }
  60. } else {
  61. cout << usage_lines(cli, execname) << '\n';
  62. }
  63. }