src/main.cpp

changeset 20
8639ccd855ba
parent 19
2c128952f198
child 21
bc8b76ca9ee9
equal deleted inserted replaced
19:2c128952f198 20:8639ccd855ba
41 "Usage: fallusmeter [OPTION]... [PATH]...\n\n" 41 "Usage: fallusmeter [OPTION]... [PATH]...\n\n"
42 "Options:\n" 42 "Options:\n"
43 " -a, --author <name> Only report this author\n" 43 " -a, --author <name> Only report this author\n"
44 " (repeat option to report multiple authors)\n" 44 " (repeat option to report multiple authors)\n"
45 " -A, --authormap <file> Apply an author mapping file\n" 45 " -A, --authormap <file> Apply an author mapping file\n"
46 " -d, --depth <num> The search depth (default: 1, max: 255)\n"
47 " -f, --fragment Output as fragment\n"
46 " -h, --help Print this help message\n" 48 " -h, --help Print this help message\n"
47 " -d, --depth <num> The search depth (default: 1, max: 255)\n"
48 " -n, --no-pull Do not pull the repositories\n" 49 " -n, --no-pull Do not pull the repositories\n"
49 " -s, --separate Output a separate heat map for each repository\n" 50 " -s, --separate Output a separate heat map for each repository\n"
50 " -y, --year <year> The year for which to create the heat map\n" 51 " -y, --year <year> The year for which to create the heat map\n"
51 " --hg <path> Path to hg binary (default: /usr/bin/hg)\n" 52 " --hg <path> Path to hg binary (default: /usr/bin/hg)\n"
52 " --git <path> Path to git binary (default: /usr/bin/git)\n\n" 53 " --git <path> Path to git binary (default: /usr/bin/git)\n\n"
76 "should \033[4monly\033[24m be used on the left-hand side. When you use the \033[1m--author\033[22m option at\n" 77 "should \033[4monly\033[24m be used on the left-hand side. When you use the \033[1m--author\033[22m option at\n"
77 "the same time, you only need to specify the new author names.\n\n" 78 "the same time, you only need to specify the new author names.\n\n"
78 "Finally, this tool prints an HTML page to stdout. A separate heap map is\n" 79 "Finally, this tool prints an HTML page to stdout. A separate heap map is\n"
79 "generated for each author showing commits across all repositories, unless the\n" 80 "generated for each author showing commits across all repositories, unless the\n"
80 "\033[1m--separate\033[22m option is specified in which case each repository is displayed with\n" 81 "\033[1m--separate\033[22m option is specified in which case each repository is displayed with\n"
81 "its own heat map.\n" 82 "its own heat map. By using the \033[1m--fragment\033[22m option, the tool only outputs a\n"
83 "single HTML div container without any header or footer that can be embedded in\n"
84 "your custom web page.\n"
82 , stderr); 85 , stderr);
83 } 86 }
84 87
85 static bool chk_arg(const char *arg, const char *opt1, const char *opt2) { 88 static bool chk_arg(const char *arg, const char *opt1, const char *opt2) {
86 return strcmp(arg, opt1) == 0 || (opt2 != nullptr && strcmp(arg, opt2) == 0); 89 return strcmp(arg, opt1) == 0 || (opt2 != nullptr && strcmp(arg, opt2) == 0);
122 fputs("missing author name\n", stderr); 125 fputs("missing author name\n", stderr);
123 return -1; 126 return -1;
124 } 127 }
125 } else if (chk_arg(argv[i], "-n", "--no-pull")) { 128 } else if (chk_arg(argv[i], "-n", "--no-pull")) {
126 settings.update_repos = false; 129 settings.update_repos = false;
130 } else if (chk_arg(argv[i], "-f", "--fragment")) {
131 settings.fragment = true;
127 } else if (chk_arg(argv[i], "-s", "--separate")) { 132 } else if (chk_arg(argv[i], "-s", "--separate")) {
128 settings.separate = true; 133 settings.separate = true;
129 } else if (chk_arg(argv[i], "-A", "--authormap")) { 134 } else if (chk_arg(argv[i], "-A", "--authormap")) {
130 if (i + 1 < argc) { 135 if (i + 1 < argc) {
131 if (settings.parse_authormap(argv[++i])) { 136 if (settings.parse_authormap(argv[++i])) {
247 } 252 }
248 heatmap.add(settings, proc.output()); 253 heatmap.add(settings, proc.output());
249 } 254 }
250 } 255 }
251 256
252 html::open(); 257 html::open(settings.fragment);
253 for (const auto &[repo, authors] : heatmap.data()) { 258 for (const auto &[repo, authors] : heatmap.data()) {
254 html::h1(repo); 259 html::h1(repo);
255 for (const auto &[author, entries] : authors) { 260 for (const auto &[author, entries] : authors) {
256 if (settings.exclude_author(author)) continue; 261 if (settings.exclude_author(author)) continue;
257 262
311 } 316 }
312 317
313 html::table_end(); 318 html::table_end();
314 } 319 }
315 } 320 }
316 html::close(); 321 html::close(settings.fragment);
317 322
318 return EXIT_SUCCESS; 323 return EXIT_SUCCESS;
319 } 324 }

mercurial