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