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.

81 lines
2.3 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 <vector>
  12. #include <cmath>
  13. #include <clipp.h>
  14. int main(int argc, char* argv[])
  15. {
  16. using namespace clipp;
  17. enum class imode { file, args, stdio, random };
  18. enum class omode { file, stdio };
  19. auto input = imode::file;
  20. auto output = omode::stdio;
  21. std::int64_t minlen = 256;
  22. std::int64_t maxlen = 1024;
  23. std::string query, subject;
  24. std::string outfile;
  25. std::vector<std::string> wrong;
  26. auto cli = (
  27. (option("-o", "--out").set(output,omode::file) &
  28. value("file", outfile)) % "write results to file"
  29. ,
  30. "read sequences from input files" % (
  31. command("-i", "--in"),
  32. value("query file", query),
  33. value("subject file", subject)
  34. ) |
  35. "specify sequences on the command line" % (
  36. command("-a", "--args").set(input,imode::args),
  37. value("query string", query),
  38. value("subject string", subject)
  39. ) |
  40. "generate random input sequences" % (
  41. command("-r", "--rand").set(input,imode::random),
  42. opt_integer("min len", minlen) &
  43. opt_integer("max len", maxlen)
  44. ) | (
  45. "read sequences from stdin" %
  46. command("-").set(input,imode::stdio)
  47. ),
  48. any_other(wrong)
  49. );
  50. if(!parse(argc,argv, cli) || !wrong.empty()) {
  51. if(!wrong.empty()) {
  52. std::cout << "Unknown command line arguments:\n";
  53. for(const auto& a : wrong) std::cout << "'" << a << "'\n";
  54. std::cout << '\n';
  55. }
  56. std::cout << make_man_page(cli, argv[0]) << '\n';
  57. return 0;
  58. }
  59. switch(input) {
  60. default:
  61. case imode::file: /* ... */ break;
  62. case imode::args: /* ... */ break;
  63. case imode::stdio: /* ... */ break;
  64. case imode::random: /* ... */ break;
  65. }
  66. switch(output) {
  67. default:
  68. case omode::stdio: /* ... */ break;
  69. case omode::file: /* ... */ break;
  70. }
  71. }