mdbx-tools: refine built-in help/usage.

Change-Id: Ia06666f48f50e088c796c85e263885ca7181c6a0
This commit is contained in:
Leonid Yuriev 2019-11-27 22:38:39 +03:00
parent 7d74aa6ae8
commit 2cfe7758cd
5 changed files with 52 additions and 35 deletions

View File

@ -759,8 +759,8 @@ bailout:
static void usage(char *prog) {
fprintf(stderr,
"usage: %s dbpath [-V] [-v] [-n] [-q] [-w] [-c] [-d] [-s subdb]\n"
" -V\t\tshow version\n"
"usage: %s [-V] [-v] [-n] [-q] [-w] [-c] [-d] [-s subdb] dbpath\n"
" -V\t\tprint version and exit\n"
" -v\t\tmore verbose, could be used multiple times\n"
" -n\t\tNOSUBDIR mode for open\n"
" -q\t\tbe quiet\n"

View File

@ -43,6 +43,19 @@ static void signal_handler(int sig) {
#endif /* !WINDOWS */
static void usage(const char *prog) {
fprintf(stderr,
"usage: %s [-V] [-q] [-c] [-n] src_path [dest_path]\n"
" -V\t\tprint version and exit\n"
" -q\t\tbe quiet\n"
" -c\t\tenable compactification (skip unused pages)\n"
" -n\t\tNOSUBDIR mode for open\n"
" src_path\tsource database\n"
" dest_path\tdestination (stdout if not specified)\n",
prog);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
int rc;
MDBX_env *env = NULL;
@ -58,6 +71,9 @@ int main(int argc, char *argv[]) {
cpflags |= MDBX_CP_COMPACT;
else if (argv[1][1] == 'q' && argv[1][2] == '\0')
quiet = true;
else if ((argv[1][1] == 'h' && argv[1][2] == '\0') ||
strcmp(argv[1], "--help") == 0)
usage(progname);
else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
printf("mdbx_copy version %d.%d.%d.%d\n"
" - source: %s %s, commit %s, tree %s\n"
@ -76,11 +92,8 @@ int main(int argc, char *argv[]) {
argc = 0;
}
if (argc < 2 || argc > 3) {
fprintf(stderr, "usage: %s [-V] [-q] [-c] [-n] srcpath [dstpath]\n",
progname);
exit(EXIT_FAILURE);
}
if (argc < 2 || argc > 3)
usage(progname);
#if defined(_WIN32) || defined(_WIN64)
SetConsoleCtrlHandler(ConsoleBreakHandlerRoutine, true);

View File

@ -160,7 +160,18 @@ static int dumpit(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
static void usage(char *prog) {
fprintf(stderr,
"usage: %s [-V] [-f output] [-l] [-n] [-p] [-a|-s subdb] dbpath\n",
"usage: %s [-V] [-q] [-f output] [-l] [-p] [-a|-s subdb] [-r] [-n] "
"dbpath\n"
" -V\t\tprint version and exit\n"
" -q\t\tbe quiet\n"
" -f\t\twrite to file instead of stdout\n"
" -l\t\tlist subDBs and exit\n"
" -p\t\tuse printable characters\n"
" -a\t\tdump main DB and all subDBs,\n"
" \t\tby default dump only the main DB\n"
" -s\t\tdump only the named subDB\n"
" -r\t\trescure mode (ignore errors to dump corrupted DB)\n"
" -n\t\tNOSUBDIR mode for open\n",
prog);
exit(EXIT_FAILURE);
}
@ -178,14 +189,6 @@ int main(int argc, char *argv[]) {
if (argc < 2)
usage(prog);
/* -a: dump main DB and all subDBs
* -s: dump only the named subDB
* -n: use NOSUBDIR flag on env_open
* -p: use printable characters
* -f: write to file instead of stdout
* -V: print version and exit
* (default) dump only the main DB
*/
while ((i = getopt(argc, argv, "af:lnps:Vrq")) != EOF) {
switch (i) {
case 'V':

View File

@ -307,7 +307,17 @@ static int readline(MDBX_val *out, MDBX_val *buf) {
static void usage(void) {
fprintf(stderr,
"usage: %s [-V] [-a] [-f input] [-n] [-s name] [-N] [-T] dbpath\n",
"usage: %s [-V] [-q] [-a] [-f file] [-s name] [-N] [-T] [-r] [-n] "
"dbpath\n"
" -V\t\tprint version and exit\n"
" -q\t\tbe quiet\n"
" -a\t\tappend records in input order\n"
" -f file\tread from file instead of stdin\n"
" -s name\tload into named subDB\n"
" -N\t\tuse NOOVERWRITE on puts\n"
" -T\t\tread plaintext\n"
" -r\t\trescure mode (ignore errors to load corrupted DB dump)\n"
" -n\t\tNOSUBDIR mode for open\n",
prog);
exit(EXIT_FAILURE);
}
@ -335,14 +345,6 @@ int main(int argc, char *argv[]) {
if (argc < 2)
usage();
/* -a: append records in input order
* -f: load file instead of stdin
* -n: use NOSUBDIR flag on env_open
* -s: load into named subDB
* -N: use NOOVERWRITE on puts
* -T: read plaintext
* -V: print version and exit
*/
while ((i = getopt(argc, argv, "af:ns:NTVrq")) != EOF) {
switch (i) {
case 'V':

View File

@ -54,7 +54,15 @@ static void prstat(MDBX_stat *ms) {
static void usage(char *prog) {
fprintf(stderr,
"usage: %s [-V] [-n] [-e] [-r[r]] [-f[f[f]]] [-a|-s subdb] dbpath\n",
"usage: %s [-V] [-e] [-r[r]] [-f[f[f]]] [-a|-s name] [-n] dbpath\n"
" -V\t\tprint version and exit\n"
" -a\t\tprint stat of main DB and all subDBs\n"
" -s name\tprint stat of only the named subDB\n"
" -e\t\tshow whole DB info\n"
" -f\t\tshow GC info\n"
" -r\t\tshow readers\n"
" \t\t(default) print stat of only the main DB\n"
" -n\t\tNOSUBDIR mode for open\n",
prog);
exit(EXIT_FAILURE);
}
@ -95,15 +103,6 @@ int main(int argc, char *argv[]) {
if (argc < 2)
usage(prog);
/* -a: print stat of main DB and all subDBs
* -s: print stat of only the named subDB
* -e: print env info
* -f: print freelist info
* -r: print reader info
* -n: use NOSUBDIR flag on env_open
* -V: print version and exit
* (default) print stat of only the main DB
*/
while ((o = getopt(argc, argv, "Vaefnrs:")) != EOF) {
switch (o) {
case 'V':