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.

115 lines
3.6 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 <sstream>
  14. // #include <clipp.h>
  15. #include "../include/clipp.h"
  16. int main(int argc, char* argv[])
  17. {
  18. using namespace clipp;
  19. using std::cout;
  20. using std::string;
  21. using std::to_string;
  22. int firstCol = 0;
  23. int docCol = 30;
  24. int lastCol = 80;
  25. auto fmtcli = (
  26. value("first column", firstCol),
  27. value("docstr column", docCol),
  28. value("last column", lastCol)
  29. );
  30. if(!parse(argc, argv, fmtcli)) {
  31. std::cout
  32. << "This program shows how clipp handles documentation formatting.\n"
  33. << "You can use the following command line interface to re-format\n"
  34. << "the documentation text of a more complex command line interface\n"
  35. << "Usage:\n" << usage_lines(fmtcli, argv[0]) << '\n';
  36. return 0;
  37. }
  38. if(docCol < firstCol) docCol = firstCol;
  39. if(lastCol <= docCol) lastCol = docCol+1;
  40. std::cout
  41. << "first column (>) " << firstCol << '\n'
  42. << "docstr column (|) " << docCol << '\n'
  43. << "last column (<) " << lastCol << '\n'
  44. << std::string(firstCol, ' ') << ">"
  45. << std::string(docCol-firstCol-1, ' ') << "|"
  46. << std::string(lastCol-docCol-1, ' ') << "<\n";
  47. auto copyMode = "copy mode:" % (
  48. command("copy") | command("move"),
  49. option("--all") % "copy all",
  50. option("--replace") % "replace existing files",
  51. option("-f", "--force") % "don't ask for confirmation"
  52. );
  53. auto compareMode = "compare mode:" % (
  54. command("compare"),
  55. (command("date") | command("content")),
  56. option("-b", "--binary") % "compare files byte by byte",
  57. option("-q", "--quick") % "use heuristics for faster comparison"
  58. );
  59. auto mergeAlgo = (
  60. command("diff") % "merge using diff" |
  61. command("patch") % "merge using patch" |
  62. ( command("content") % "merge based on content",
  63. "content based merge options:" % (
  64. option("--git-style") % "emulate git's merge behavior",
  65. option("-m", "--marker") & value("marker") % "merge marker symbol"
  66. )
  67. )
  68. );
  69. auto mergeMode = "merge mode:" % (
  70. command("merge"),
  71. mergeAlgo,
  72. required("-o") & value("outdir") % "target directory for merge result",
  73. option("--show-conflicts") % "show merge conflicts during run"
  74. );
  75. auto firstOpt = "user interface options:" % (
  76. option("-v", "--verbose") % "show detailed output",
  77. option("-i", "--interactive") % "use interactive mode"
  78. );
  79. auto lastOpt = "mode-independent options:" % (
  80. values("files") % "input files",
  81. option("-r", "--recursive") % "descend into subdirectories",
  82. option("-h", "--help") % "show help"
  83. );
  84. auto cli = (
  85. firstOpt,
  86. copyMode | compareMode | mergeMode | command("list"),
  87. lastOpt
  88. );
  89. parse(argc, argv, fmtcli);
  90. auto fmt = doc_formatting{}
  91. .line_spacing(0)
  92. .paragraph_spacing(1)
  93. .first_column(firstCol)
  94. .doc_column(docCol)
  95. .last_column(lastCol);
  96. cout << make_man_page(cli, argv[0], fmt) << '\n';
  97. // cout << documentation(cli, fmt) << '\n';
  98. // cout << usage_lines(cli, argv[0], fmt) << '\n';
  99. }