Improved --help and added --version

I added a --version longoption that says some stuff about the version and the copyright and the people who made mkp224o,

Also,

I made changes to the helpfile:
~ It now fits in small terminals that are 80 chars wide without being screen wrapped
~ It looks pretty like GNU utilities now
~ It has a couple less typos
~ It now has a link to the mkp224o homepage and a link to the issues page
~ And it now mentions the --help and --usage longoptions (and also the new --version longoption that I added)
This commit is contained in:
N1xis10t 2021-08-02 13:01:25 -06:00 committed by GitHub
parent fc6285523f
commit ec73643820
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

93
main.c
View file

@ -83,40 +83,70 @@ VEC_STRUCT(tstatsvec,struct tstatstruct);
static void printhelp(FILE *out,const char *progname) static void printhelp(FILE *out,const char *progname)
{ {
fprintf(out, fprintf(out,
"Usage: %s filter [filter...] [options]\n" "Usage: %s FILTER [FILTER...] [OPTION]\n"
" %s -f filterfile [options]\n" " %s -f FILTERFILE [OPTION]\n"
"Options:\n" "\n"
"\t-h - print help to stdout and quit\n" " -f, =FILTERFILE specify filter file which contains filters separated\n"
"\t-f - specify filter file which contains filters separated by newlines\n" " by newlines\n"
"\t-D - deduplicate filters\n" " -D, deduplicate filters\n"
"\t-q - do not print diagnostic output to stderr\n" " -q, do not print diagnostic output to stderr\n"
"\t-x - do not print onion names\n" " -x, do not print onion names\n"
"\t-v - print more diagnostic data\n" " -v, print more diagnostic data\n"
"\t-o filename - output onion names to specified file (append)\n" " -o, =FILENAME output onion names to specified file (append)\n"
"\t-O filename - output onion names to specified file (overwrite)\n" " -O, =FILENAME output onion names to specified file (overwrite)\n"
"\t-F - include directory names in onion names output\n" " -F, include directory names in onion names output\n"
"\t-d dirname - output directory\n" " -d, =DIRNAME output directory\n"
"\t-t numthreads - specify number of threads to utilise (default - CPU core count or 1)\n" " -t, =NUMTHREADS specify number of threads to utilise (default - CPU\n"
"\t-j numthreads - same as -t\n" " core count or 1)\n"
"\t-n numkeys - specify number of keys (default - 0 - unlimited)\n" " -j, =NUMTHREADS same as -t\n"
"\t-N numwords - specify number of words per key (default - 1)\n" " -n, =NUMKEYS specify number of keys (default - 0 - unlimited)\n"
"\t-Z - use \"slower\" key generation method (initial default)\n" " -N, =NUMWORDS specify number of words per key (default - 1)\n"
"\t-z - use \"faster\" key generation method (later default)\n" " -Z, use \"slower\" key generation method (initial default)\n"
"\t-B - use batching key generation method (>10x faster than -z, current default)\n" " -z, use \"faster\" key generation method (later default)\n"
"\t-s - print statistics each 10 seconds\n" " -B, use batching key generation method (>10x faster than\n"
"\t-S t - print statistics every specified ammount of seconds\n" " -z, current default)\n"
"\t-T - do not reset statistics counters when printing\n" " -s, print statistics each 10 seconds\n"
"\t-y - output generated keys in YAML format instead of dumping them to filesystem\n" " -S, =SECONDS print statistics every specified amount of seconds\n"
"\t-Y [filename [host.onion]] - parse YAML encoded input and extract key(s) to filesystem\n" " -T, do not reset statistics counters when printing\n"
"\t--rawyaml - raw (unprefixed) public/secret keys for -y/-Y (may be useful for tor controller API)\n" " -y, output generated keys in YAML format instead of\n"
" dumping them to filesystem\n"
" -Y, =[FILENAME [host.onion]]\n"
" parse YAML encoded input and extract key(s) to\n"
" filesystem\n"
#ifdef PASSPHRASE #ifdef PASSPHRASE
"\t-p passphrase - use passphrase to initialize the random seed with\n" " -p, =PASSPHRASE use passphrase to initialize the random seed with\n"
"\t-P - same as -p, but takes passphrase from PASSPHRASE environment variable\n" " -P, same as -p, but takes passphrase from PASSPHRASE\n"
" environment variable\n"
#endif #endif
" --rawyaml raw (unprefixed) public/secret keys for -y/-Y\n"
" (may be useful for tor controller API)\n"
" -h, --help print help to stdout and quit\n"
" --usage same as --help\n"
" --version print version information to stdout and exit\n"
"\n"
"Report bugs at: <https://github.com/cathugger/mkp224o/issues>\n"
"mkp224o home page: <https://github.com/cathugger/mkp224o>\n"
,progname,progname); ,progname,progname);
fflush(out); fflush(out);
} }
static void printversion(FILE *out)
{
fprintf(out,
"mkp224o 1.5.0\n"
"Copyright (C) 2021 cathugger\n"
"License public domain:\n"
" CC0 1.0 <https://creativecommons.org/publicdomain/zero/1.0/>\n"
"This is free software: you are free to change and redistribute it.\n"
"There is NO WARRANTY, to the extent permitted by law.\n"
"\n"
"mkp224o was mostly written by cathugger, but some other people helped too.\n"
"Please visit the mkp224o home page to find additional acknowledgements:\n"
"<https://github.com/cathugger/mkp224o>\n"
);
fflush(out);
}
static void e_additional(void) static void e_additional(void)
{ {
fprintf(stderr,"additional argument required\n"); fprintf(stderr,"additional argument required\n");
@ -246,8 +276,13 @@ int main(int argc,char **argv)
printhelp(stdout,progname); printhelp(stdout,progname);
exit(0); exit(0);
} }
else if (!strcmp(arg,"rawyaml")) else if (!strcmp(arg,"rawyaml")) {
yamlraw = 1; yamlraw = 1;
}
else if (!strcmp(arg,"version")) {
printversion(stdout);
exit(0);
}
else { else {
fprintf(stderr,"unrecognised argument: --%s\n",arg); fprintf(stderr,"unrecognised argument: --%s\n",arg);
exit(1); exit(1);