1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "core.h"
#include "args.h"
struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"destdir", required_argument, 0, 'd'},
{"verbose", no_argument, 0, 'v'},
{"unbuffered", no_argument, 0, 'U'},
{"web", no_argument, 0, 'w'},
{"micromamba-download-url", required_argument, 0, OPT_MICROMAMBA_DOWNLOAD_URL},
{0, 0, 0, 0},
};
const char *long_options_help[] = {
"Display this usage statement",
"Destination directory",
"Increase output verbosity",
"Disable line buffering",
"Generate HTML indexes (requires pandoc)",
"Set micromamba download URL",
NULL,
};
void usage(char *name) {
const int maxopts = sizeof(long_options) / sizeof(long_options[0]);
char *opts = calloc(maxopts + 1, sizeof(char));
if (!opts) {
SYSERROR("Unable to allocate memory for options array");
exit(1);
}
for (int i = 0, n = 0; i < maxopts; i++) {
if (isalnum(long_options[i].val)) {
opts[n] = (char) long_options[i].val;
n++;
}
}
printf("usage: %s [-%s] {{STASIS_ROOT} ...}\n", name, opts);
guard_free(opts);
for (int i = 0; i < maxopts - 1; i++) {
char line[255] = {0};
snprintf(line, sizeof(line), " --%s %s%c %s",
long_options[i].name,
isalnum(long_options[i].val) ? "-" : "",
isalnum(long_options[i].val) ? long_options[i].val : ' ',
long_options_help[i]);
puts(line);
}
}
|