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.

41 lines
1.1 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 <clipp.h>
  13. int main(int argc, char* argv[])
  14. {
  15. using namespace clipp;
  16. using std::cout;
  17. std::string outfile = "a.out";
  18. bool align = false;
  19. auto cli = (
  20. (option("-o", "--out") & value("output file", outfile)) % "output filename",
  21. with_prefix("-f", option("align") >> [&]{ align = true; } |
  22. option("noalign") >> [&]{ align = false; } ) % "control alignment"
  23. );
  24. if(parse(argc, argv, cli)) {
  25. cout << "write to " << outfile
  26. << " with" << (align ? "" : "out") << " alignment.\n";
  27. }
  28. else {
  29. auto fmt = doc_formatting{}
  30. .merge_alternative_flags_with_common_prefix(true);
  31. cout << make_man_page(cli, argv[0], fmt) << '\n';
  32. }
  33. }