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.

78 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. auto copyMode = "copy mode:" % (
  20. command("copy") | command("move"),
  21. option("--all") % "copy all",
  22. option("--replace") % "replace existing files",
  23. option("-f", "--force") % "don't ask for confirmation"
  24. );
  25. auto compareMode = "compare mode:" % (
  26. command("compare"),
  27. (command("date") | command("content")),
  28. option("-b", "--binary") % "compare files byte by byte",
  29. option("-q", "--quick") % "use heuristics for faster comparison"
  30. );
  31. auto mergeAlgo = (
  32. command("diff") % "merge using diff" |
  33. command("patch") % "merge using patch" |
  34. ( command("content") % "merge based on content",
  35. "content based merge options:" % (
  36. option("--git-style") % "emulate git's merge behavior",
  37. option("-m", "--marker") & value("marker") % "merge marker symbol"
  38. )
  39. )
  40. );
  41. auto mergeMode = "merge mode:" % (
  42. command("merge"),
  43. mergeAlgo,
  44. required("-o") & value("outdir") % "target directory for merge result",
  45. option("--show-conflicts") % "show merge conflicts during run"
  46. );
  47. auto firstOpt = "user interface options:" % (
  48. option("-v", "--verbose") % "show detailed output",
  49. option("-i", "--interactive") % "use interactive mode"
  50. );
  51. auto lastOpt = "mode-independent options:" % (
  52. values("files") % "input files",
  53. option("-r", "--recursive") % "descend into subdirectories",
  54. option("-h", "--help") % "show help"
  55. );
  56. auto cli = (
  57. firstOpt,
  58. copyMode | compareMode | mergeMode | command("list"),
  59. lastOpt
  60. );
  61. if(parse(argc, argv, cli)) {
  62. // program logic...
  63. } else {
  64. auto fmt = doc_formatting{}.doc_column(31).last_column(80);
  65. cout << make_man_page(cli, argv[0], fmt) << '\n';
  66. }
  67. }