5 #include "biawebdocumenttree.hpp"
6 #include "biawebstrings.hpp"
8 // Class to parse the command line options and run DocumentTree
14 std::string target_dir;
15 std::string template_dir;
16 std::string source_dir;
19 // main constructor - build options from command line
20 Main (int argc, char **argv) ;
22 // run the program with the options built from constructor
23 // and return the result
27 // Execute the program and return the result
29 // if usage of the program is to be displayed then display it and quit
30 if (this->display_usage == true ) {
31 std::cerr << PROGRAM_USAGE;
32 std::cerr << this->app_name << " " << PROGRAM_ARGS << std::endl;
33 std::cerr << PROGRAM_EXPLANATION << std::endl;
36 // else run the program
38 // timing for the program
39 std::chrono::time_point<std::chrono::steady_clock> t1
40 (std::chrono::steady_clock::now());
42 // create a blank document tree and build the tree from source dir
43 std::unique_ptr<DocumentTree> doctree (new DocumentTree(""));
44 doctree.get()->document_tree_builder (this->source_dir);
45 // if not quiet mode, display the tree visualization
46 if (! this->quiet_mode) {
47 std::cout << VISUALIZE_TREE << std::endl;
48 doctree.get()->visualize_tree ();
50 // generate the template
51 Template t (this->template_dir);
52 doctree.get()->create_tree_html (&t, this->target_dir);
54 if (! this->quiet_mode)
55 std::cout << OUTPUT_IN << " " << this->target_dir << std::endl;
58 std::chrono::time_point<std::chrono::steady_clock> t2
59 (std::chrono::steady_clock::now());
60 std::chrono::duration<double> dur (t2 - t1);
61 // display the execution time
62 if (! this->quiet_mode)
63 std::cout << GENERATED_IN << dur.count() << std::endl;
68 // build the options from command line using getopt
69 Main::Main (int argc, char **argv) {
70 this->display_usage = true;
71 this->quiet_mode = false;
72 this->app_name = argv[0];
73 this->source_dir = "";
74 this->target_dir = "";
75 this->template_dir = "";
78 while ((c = getopt (argc, argv, "i:t:o:q")) != -1) {
80 case 'i' : this->source_dir = optarg;
82 case 't' : this->template_dir = optarg;
84 case 'o' : this->target_dir = optarg;
86 case 'q' : this->quiet_mode = true;
89 // if the user has not given the required parameters then set to display usage
91 if (this->source_dir.empty () || this->target_dir.empty ()
92 || this->template_dir.empty ())
93 this->display_usage = true;
95 this->display_usage = false;