src/main.cpp

changeset 73
707f42bb0484
parent 71
39644afa3808
child 75
857af79337d5
equal deleted inserted replaced
72:93de83b09c2d 73:707f42bb0484
36 36
37 #include <numeric> 37 #include <numeric>
38 38
39 using namespace std::chrono; 39 using namespace std::chrono;
40 40
41 static constexpr auto program_version = "1.1.2"; 41 static constexpr auto program_version = "1.2.0-preview";
42 42
43 static void print_help() { 43 static void print_help() {
44 fputs( 44 fputs(
45 "Usage: repoheat [OPTION]... [PATH]...\n\n" 45 "Usage: repoheat [OPTION]... [PATH]...\n\n"
46 "Options:\n" 46 "Options:\n"
50 " -d, --depth <num> The search depth (default: 1, max: 255)\n" 50 " -d, --depth <num> The search depth (default: 1, max: 255)\n"
51 " -f, --fragment [indent] Output as fragment\n" 51 " -f, --fragment [indent] Output as fragment\n"
52 " -h, --help Print this help message\n" 52 " -h, --help Print this help message\n"
53 " -p, --pull Try to pull the repositories\n" 53 " -p, --pull Try to pull the repositories\n"
54 " -s, --separate Output a separate heat map for each repository\n" 54 " -s, --separate Output a separate heat map for each repository\n"
55 " --styles-and-script Output the default CSS and Javascript and quit\n"
55 " -V, --version Output the version of this program and exit\n" 56 " -V, --version Output the version of this program and exit\n"
56 " -y, --year <year> The year for which to create the heat map\n" 57 " -y, --year <year> The year for which to create the heat map\n"
57 " --hg <path> Path to hg binary (default: /usr/bin/hg)\n" 58 " --hg <path> Path to hg binary (default: /usr/bin/hg)\n"
58 " --git <path> Path to git binary (default: /usr/bin/git)\n\n" 59 " --git <path> Path to git binary (default: /usr/bin/git)\n\n"
59 "Scans all specified paths recursively for Mercurial and Git repositories and\n" 60 "Scans all specified paths recursively for Mercurial and Git repositories and\n"
86 "\033[1m--separate\033[22m option is specified in which case each repository is displayed with\n" 87 "\033[1m--separate\033[22m option is specified in which case each repository is displayed with\n"
87 "its own heat map. By using the \033[1m--fragment\033[22m option, the tool only outputs a\n" 88 "its own heat map. By using the \033[1m--fragment\033[22m option, the tool only outputs a\n"
88 "single HTML div container without any header or footer that can be embedded in\n" 89 "single HTML div container without any header or footer that can be embedded in\n"
89 "your custom web page. You can optionally specify an indentation for that\n" 90 "your custom web page. You can optionally specify an indentation for that\n"
90 "container (default is 0 and maximum is 12).\n" 91 "container (default is 0 and maximum is 12).\n"
92 "When you want to combine this with the default style and scripts, you can use\n"
93 "the \033[1m--styles-and-script\033[22m option print the defaults to stdout and redirect them\n"
94 "into a file when you are composing your custom HTML page.\n"
91 , stderr); 95 , stderr);
92 } 96 }
93 97
94 static bool chk_arg(const char *arg, const char *opt1, const char *opt2) { 98 static bool chk_arg(const char *arg, const char *opt1, const char *opt2) {
95 return strcmp(arg, opt1) == 0 || (opt2 != nullptr && strcmp(arg, opt2) == 0); 99 return strcmp(arg, opt1) == 0 || (opt2 != nullptr && strcmp(arg, opt2) == 0);
169 settings.git.assign(argv[++i]); 173 settings.git.assign(argv[++i]);
170 } else { 174 } else {
171 fputs("--git is expecting a path\n", stderr); 175 fputs("--git is expecting a path\n", stderr);
172 return -1; 176 return -1;
173 } 177 }
178 } else if (chk_arg(argv[i], "--styles-and-script", nullptr)) {
179 settings.styles_and_script = true;
180 if (argc != 2) {
181 fputs("Error: --styles-and-script must be the only option when present\n", stderr);
182 return -1;
183 }
174 } else if (argv[i][0] == '-') { 184 } else if (argv[i][0] == '-') {
175 fprintf(stderr, "Unknown option: %s\n", argv[i]); 185 fprintf(stderr, "Unknown option: %s\n", argv[i]);
176 return -1; 186 return -1;
177 } else { 187 } else {
178 settings.paths.emplace_back(argv[i]); 188 settings.paths.emplace_back(argv[i]);
189 int main(int argc, char *argv[]) { 199 int main(int argc, char *argv[]) {
190 // parse settings 200 // parse settings
191 fm::settings settings; 201 fm::settings settings;
192 if (int result = parse_args(settings, argc, argv); result != 0) { 202 if (int result = parse_args(settings, argc, argv); result != 0) {
193 return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS; 203 return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
204 }
205
206 // check special options
207 if (settings.styles_and_script) {
208 html::styles_and_script();
209 return 0;
194 } 210 }
195 211
196 // check hg and git 212 // check hg and git
197 fm::process proc; 213 fm::process proc;
198 proc.setbin(settings.hg); 214 proc.setbin(settings.hg);

mercurial