bin: sync usage and keep it consistent in all utils.

This commit is contained in:
Juan RP 2020-04-20 21:25:14 +02:00
parent d5251a9c23
commit 9b695433a0
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368
15 changed files with 285 additions and 232 deletions

View File

@ -44,13 +44,13 @@ usage(bool fail)
" -C --config <dir> Path to confdir (xbps.d)\n" " -C --config <dir> Path to confdir (xbps.d)\n"
" -d --debug Debug mode shown to stderr\n" " -d --debug Debug mode shown to stderr\n"
" -g --group <name> Group of alternatives to match\n" " -g --group <name> Group of alternatives to match\n"
" -h --help Print usage help\n" " -h --help Show usage\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r --rootdir <dir> Full path to rootdir\n"
" -v --verbose Verbose messages\n" " -v --verbose Verbose messages\n"
" -V --version Show XBPS version\n" " -V --version Show XBPS version\n"
"MODE\n" "MODE\n"
" -l --list [PKG] List all alternatives or from PKG\n" " -l --list [PKG] List all alternatives or from PKG\n"
" -s --set PKG Set alternatives for PKG\n\n"); " -s --set PKG Set alternatives for PKG\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -73,29 +73,28 @@ xstrdup(const char *src)
} }
static int static int
show_usage(const char *prog) show_usage(const char *prog, bool fail)
{ {
fprintf(stderr, fprintf(stderr,
"Usage: %s [OPTIONS] [FILES...]\n\n" "Usage: %s [OPTIONS] [FILES...]\n\n"
"OPTIONS:\n" "OPTIONS:\n"
" -h --help Show this helpful help-message for help.\n" " -h, --help Show usage\n"
" -C --config <dir> Set path to xbps.d\n" " -C, --config <dir> Set path to xbps.d\n"
" -D --distdir <dir> Set (or override) the path to void-packages\n" " -D, --distdir <dir> Set (or override) the path to void-packages\n"
" (defaults to ~/void-packages).\n" " (defaults to ~/void-packages)\n"
" -d --debug Enable debug output to stderr.\n" " -d, --debug Enable debug output to stderr\n"
" -e --removed List packages present in repos, but not in distdir.\n" " -e, --removed List packages present in repos, but not in distdir\n"
" -f --format <fmt> Output format.\n" " -f, --format <fmt> Output format\n"
" -I --installed Check for outdated packages in rootdir, rather\n" " -I, --installed Check for outdated packages in rootdir, rather\n"
" than in the XBPS repositories.\n" " than in the XBPS repositories\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d.\n" " -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -m --manual Only process listed files.\n" " -m, --manual Only process listed files\n"
" -R --repository=<url> Append repository to the head of repository list.\n" " -R, --repository=<url> Append repository to the head of repository list\n"
" -r --rootdir <dir> Set root directory (defaults to /).\n" " -r, --rootdir <dir> Set root directory (defaults to /)\n"
" -s --show-all List all packages, in the format 'pkgname repover srcver'.\n" " -s, --show-all List all packages, in the format 'pkgname repover srcver'\n"
"\n [FILES...] Extra packages to process with the outdated\n" "\n [FILES...] Extra packages to process with the outdated\n"
" ones (only processed if missing).\n\n", " ones (only processed if missing).\n", prog);
prog); return fail ? EXIT_FAILURE: EXIT_SUCCESS;
return EXIT_FAILURE;
} }
static void static void
@ -728,7 +727,7 @@ main(int argc, char **argv)
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'h': case 'h':
return show_usage(prog); return show_usage(prog, false);
case 'C': case 'C':
rcv.xbps_conf = xstrdup(optarg); rcv.xbps_conf = xstrdup(optarg);
break; break;
@ -765,8 +764,9 @@ main(int argc, char **argv)
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case '?':
default: default:
return show_usage(prog); return show_usage(prog, true);
} }
} }
/* /*

View File

@ -68,54 +68,49 @@ static xbps_dictionary_t pkg_propsd, pkg_filesd, all_filesd;
static const char *destdir; static const char *destdir;
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(void) usage(bool fail)
{ {
fprintf(stdout, fprintf(stdout,
"Usage: %s [OPTIONS] -A <arch> -n <pkgver> -s \"<desc>\" destdir\n\n" "Usage: %s [OPTIONS] -A <arch> -n <pkgver> -s \"<desc>\" destdir\n\n"
"OPTIONS\n" "OPTIONS\n"
" -A --architecture Package architecture (e.g: noarch, i686, etc).\n" " -A, --architecture Package architecture (e.g: noarch, i686, etc)\n"
" -B --built-with Package builder string (e.g: xbps-src-30).\n" " -B, --built-with Package builder string (e.g: xbps-src-30)\n"
" -C --conflicts Conflicts (blank separated list,\n" " -C, --conflicts Conflicts (blank separated list, e.g: 'foo>=2.0 blah<=2.0')\n"
" e.g: 'foo>=2.0 blah<=2.0').\n" " -c, --changelog Changelog URL\n"
" -c --changelog Changelog URL.\n" " -D, --dependencies Dependencies (blank separated list, e.g: 'foo>=1.0_1 blah<2.1')\n"
" -D --dependencies Dependencies (blank separated list,\n" " -F, --config-files Configuration files (blank separated list,\n"
" e.g: 'foo>=1.0_1 blah<2.1').\n" " e.g '/etc/foo.conf /etc/foo-blah.conf')\n"
" -F --config-files Configuration files (blank separated list,\n" " -H, --homepage Homepage\n"
" e.g '/etc/foo.conf /etc/foo-blah.conf').\n" " -h, --help Show usage\n"
" -H --homepage Homepage.\n" " -l, --license License\n"
" -h --help Show help.\n" " -M, --mutable-files Mutable files list (blank separated list,\n"
" -l --license License.\n" " e.g: '/usr/lib/foo /usr/bin/blah')\n"
" -M --mutable-files Mutable files list (blank separated list,\n" " -m, --maintainer Maintainer\n"
" e.g: '/usr/lib/foo /usr/bin/blah').\n" " -n, --pkgver Package name/version tuple (e.g `foo-1.0_1')\n"
" -m --maintainer Maintainer.\n" " -P, --provides Provides (blank separated list, e.g: 'foo-9999 blah-1.0')\n"
" -n --pkgver Package name/version tuple (e.g `foo-1.0_1').\n" " -p, --preserve Enable package preserve boolean\n"
" -P --provides Provides (blank separated list,\n" " -q, --quiet Work silently\n"
" e.g: 'foo-9999 blah-1.0').\n" " -R, --replaces Replaces (blank separated list, e.g: 'foo>=1.0 blah<2.0')\n"
" -p --preserve Enable package preserve boolean.\n" " -r, --reverts Reverts (blank separated list, e.g: '1.0_1 2.0_3')\n"
" -q --quiet Work silently.\n" " -S, --long-desc Long description (80 cols per line)\n"
" -R --replaces Replaces (blank separated list,\n" " -s, --desc Short description (max 80 characters)\n"
" e.g: 'foo>=1.0 blah<2.0').\n" " -t, --tags A list of tags/categories (blank separated list)\n"
" -r --reverts Reverts (blank separated list,\n" " -V, --version Show XBPS version\n"
" e.g: '1.0_1 2.0_3').\n" " --alternatives List of available alternatives this pkg provides\n"
" -S --long-desc Long description (80 cols per line).\n" " This expects a blank separated list of <name>:<symlink>:<target>, e.g\n"
" -s --desc Short description (max 80 characters).\n" " 'vi:/usr/bin/vi:/usr/bin/vim foo:/usr/bin/foo:/usr/bin/blah'\n"
" -t --tags A list of tags/categories (blank separated list).\n" " --build-options A string with the used build options\n"
" -V --version Prints XBPS release version.\n" " --compression Compression format: none, gzip, bzip2, lz4, xz, zstd (default)\n"
" --alternatives List of available alternatives this pkg provides.\n" " --shlib-provides List of provided shared libraries (blank separated list,\n"
" This expects a blank separated list of <name>:<symlink>:<target>, e.g\n" " e.g 'libfoo.so.1 libblah.so.2')\n"
" 'vi:/usr/bin/vi:/usr/bin/vim foo:/usr/bin/foo:/usr/bin/blah'.\n" " --shlib-requires List of required shared libraries (blank separated list,\n"
" --build-options A string with the used build options.\n" " e.g 'libfoo.so.1 libblah.so.2')\n\n"
" --compression Compression format: none, gzip, bzip2, lz4, xz, zstd (default).\n"
" --shlib-provides List of provided shared libraries (blank separated list,\n"
" e.g 'libfoo.so.1 libblah.so.2').\n"
" --shlib-requires List of required shared libraries (blank separated list,\n"
" e.g 'libfoo.so.1 libblah.so.2').\n\n"
"NOTE:\n" "NOTE:\n"
" At least three flags are required: architecture, pkgver and desc.\n\n" " At least three flags are required: architecture, pkgver and desc.\n\n"
"EXAMPLE:\n" "EXAMPLE:\n"
" $ %s -A noarch -n foo-1.0_1 -s \"foo pkg\" destdir\n", " $ %s -A noarch -n foo-1.0_1 -s \"foo pkg\" destdir\n",
_PROGNAME, _PROGNAME); _PROGNAME, _PROGNAME);
exit(EXIT_FAILURE); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
@ -866,7 +861,7 @@ main(int argc, char **argv)
srcrevs = optarg; srcrevs = optarg;
break; break;
case 'h': case 'h':
usage(); usage(false);
break; break;
case 'H': case 'H':
homepage = optarg; homepage = optarg;
@ -927,11 +922,14 @@ main(int argc, char **argv)
break; break;
case '?': case '?':
default: default:
usage(); usage(true);
/* NOTREACHED */
} }
} }
if (argc == optind) if (argc == optind) {
usage(); usage(true);
/* NOTREACHED */
}
destdir = argv[optind]; destdir = argv[optind];

View File

@ -110,25 +110,25 @@ die(const char *fmt, ...)
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(void) usage(bool fail)
{ {
fprintf(stdout, fprintf(stdout,
"Usage: xbps-dgraph [OPTIONS] [MODE] <pkgname>\n\n" "Usage: xbps-dgraph [OPTIONS] [MODE] <pkgname>\n\n"
"OPTIONS\n" "OPTIONS\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -c --graph-config <file> Path to the graph configuration file\n" " -c, --graph-config <file> Path to the graph configuration file\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -h --help Print help usage\n" " -h, --help Show usage\n"
" -M --memory-sync Remote repository data is fetched and stored\n" " -M, --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n" " in memory, ignoring on-disk repodata archives.\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -R --repository Enable repository mode. This mode explicitly\n" " -R, --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n" " looks for packages in repositories.\n"
"MODE\n" "MODE\n"
" -g --gen-config Generate a configuration file\n" " -g, --gen-config Generate a configuration file\n"
" -f --fulldeptree Generate a dependency graph\n" " -f, --fulldeptree Generate a dependency graph\n"
" -m --metadata Generate a metadata graph (default mode)\n\n"); " -m, --metadata Generate a metadata graph (default mode)\n");
exit(EXIT_FAILURE); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
static const char * static const char *
@ -558,6 +558,9 @@ main(int argc, char **argv)
/* Generate conf file. */ /* Generate conf file. */
generate_conf_file(); generate_conf_file();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h':
usage(false);
/* NOTREACHED */
case 'M': case 'M':
flags |= XBPS_FLAG_REPOS_MEMSYNC; flags |= XBPS_FLAG_REPOS_MEMSYNC;
break; break;
@ -578,7 +581,8 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case '?': case '?':
default: default:
usage(); usage(true);
/* NOTREACHED */
} }
} }
@ -586,7 +590,8 @@ main(int argc, char **argv)
argv += optind; argv += optind;
if (!argc && !opmode) { if (!argc && !opmode) {
usage(); usage(true);
/* NOTREACHED */
} }
pkg = *argv; pkg = *argv;

View File

@ -34,19 +34,18 @@
#include <xbps.h> #include <xbps.h>
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(void) usage(bool fail)
{ {
fprintf(stdout, fprintf(stdout,
"Usage: xbps-digest [options] [file] [file+N]\n" "Usage: xbps-digest [options] [file] [file+N]\n"
"\n" "\n"
"OPTIONS:\n" "OPTIONS\n"
" -h\t\tShow usage()\n" " -h, --help Show usage\n"
" -m <sha256>\tSelects the digest mode, sha256 (default)\n" " -m, --mode <sha256> Selects the digest mode, sha256 (default)\n"
" -V\t\tPrints the xbps release version\n" " -V, --version Show XBPS version\n"
"\n" "\nNOTES\n"
"NOTES\n" " If [file] not set, reads from stdin\n");
" If [file] not set, reads from stdin.\n"); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
exit(EXIT_FAILURE);
} }
int int
@ -56,11 +55,17 @@ main(int argc, char **argv)
char sha256[XBPS_SHA256_SIZE]; char sha256[XBPS_SHA256_SIZE];
const char *mode = NULL, *progname = argv[0]; const char *mode = NULL, *progname = argv[0];
const struct option longopts[] = { const struct option longopts[] = {
{ "mode", required_argument, NULL, 'm' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
while ((c = getopt_long(argc, argv, "m:hV", longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, "m:hV", longopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'h':
usage(false);
/* NOTREACHED */
case 'm': case 'm':
mode = optarg; mode = optarg;
break; break;
@ -68,9 +73,9 @@ main(int argc, char **argv)
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case '?': case '?':
case 'h':
default: default:
usage(); usage(true);
/* NOTREACHED */
} }
} }

View File

@ -132,7 +132,7 @@ addItem(const char *pkgn)
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(const char *progname) usage(const char *progname, bool fail)
{ {
fprintf(stderr, "Usage: %s [OPTIONS] /path/to/void-packages [pkg pkg+N]\n\n" fprintf(stderr, "Usage: %s [OPTIONS] /path/to/void-packages [pkg pkg+N]\n\n"
"OPTIONS\n" "OPTIONS\n"
@ -142,7 +142,7 @@ usage(const char *progname)
" -V, --verbose Enable verbose mode\n" " -V, --verbose Enable verbose mode\n"
" -v, --version Show XBPS version\n" " -v, --version Show XBPS version\n"
" -h, --help Show usage\n", progname); " -h, --help Show usage\n", progname);
exit(EXIT_FAILURE); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
/* /*
@ -577,6 +577,9 @@ main(int argc, char **argv)
while ((ch = getopt_long(argc, argv, "hj:l:svV", longopts, NULL)) != -1) { while ((ch = getopt_long(argc, argv, "hj:l:svV", longopts, NULL)) != -1) {
switch (ch) { switch (ch) {
case 'h':
usage(progname, false);
/* NOTREACHED */
case 's': case 's':
RebuildSystem = true; RebuildSystem = true;
break; break;
@ -592,18 +595,18 @@ main(int argc, char **argv)
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case '?':
default: default:
usage(progname); usage(progname, true);
/* NOT REACHED */ /* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc < 1) { if (argc < 1) {
usage(progname); usage(progname, true);
/* NOT REACHED */ /* NOTREACHED */
} }
/* /*

View File

@ -37,18 +37,18 @@
#include "../xbps-install/defs.h" #include "../xbps-install/defs.h"
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(void) usage(bool fail)
{ {
fprintf(stdout, fprintf(stdout,
"Usage: xbps-fetch [options] <url> <url+N>\n\n" "Usage: xbps-fetch [options] <url> <url+N>\n\n"
"OPTIONS:\n" "OPTIONS\n"
" -d\t\tEnable debug messages to stderr\n" " -d, --debug Enable debug messages to stderr\n"
" -h\t\tShow usage()\n" " -h, --help Show usage\n"
" -o <file>\tRename downloaded file to <file>\n" " -o, --out <file> Rename downloaded file to <file>\n"
" -s\t\tOutput sha256sums of the files\n" " -s, --sha256 Output sha256sums of the files\n"
" -v\t\tEnable verbose output\n" " -v, --verbose Enable verbose output\n"
" -V\t\tPrints the xbps release version\n"); " -V, --version Show XBPS version\n");
exit(EXIT_FAILURE); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
static char * static char *
@ -92,11 +92,20 @@ main(int argc, char **argv)
struct xferstat xfer = {}; struct xferstat xfer = {};
const char *filename = NULL, *progname = argv[0]; const char *filename = NULL, *progname = argv[0];
const struct option longopts[] = { const struct option longopts[] = {
{ "out", required_argument, NULL, 'o' },
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "sha256", no_argument, NULL, 's' },
{ "version", no_argument, NULL, 'V' },
{ "verbose", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
while ((c = getopt_long(argc, argv, "o:dhsVv", longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, "o:dhsVv", longopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'h':
usage(false);
/* NOTREACHED */
case 'o': case 'o':
filename = optarg; filename = optarg;
break; break;
@ -113,17 +122,19 @@ main(int argc, char **argv)
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case '?': case '?':
case 'h':
default: default:
usage(); usage(true);
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (!argc) if (!argc) {
usage(); usage(true);
/* NOTREACHED */
}
/* /*
* Initialize libxbps. * Initialize libxbps.

View File

@ -43,29 +43,29 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n" "Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n"
"OPTIONS\n" "OPTIONS\n"
" -A --automatic Set automatic installation mode\n" " -A, --automatic Set automatic installation mode\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -c --cachedir <dir> Path to cachedir\n" " -c, --cachedir <dir> Path to cachedir\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -D --download-only Download packages and check integrity, nothing else\n" " -D, --download-only Download packages and check integrity, nothing else\n"
" -f --force Force package re-installation\n" " -f, --force Force package re-installation\n"
" If specified twice, all files will be overwritten.\n" " If specified twice, all files will be overwritten.\n"
" -h --help Print help usage\n" " -h, --help Show usage\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d\n" " -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -I --ignore-file-conflicts Ignore detected file conflicts\n" " -I, --ignore-file-conflicts Ignore detected file conflicts\n"
" -U --unpack-only Unpack packages in transaction, do not configure them\n" " -U, --unpack-only Unpack packages in transaction, do not configure them\n"
" -M --memory-sync Remote repository data is fetched and stored\n" " -M, --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives\n" " in memory, ignoring on-disk repodata archives\n"
" -n --dry-run Dry-run mode\n" " -n, --dry-run Dry-run mode\n"
" -R,--repository <url> Add repository to the top of the list\n" " -R, --repository <url> Add repository to the top of the list\n"
" This option can be specified multiple times\n" " This option can be specified multiple times\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" --reproducible Enable reproducible mode in pkgdb\n" " --reproducible Enable reproducible mode in pkgdb\n"
" -S --sync Sync remote repository index\n" " -S, --sync Sync remote repository index\n"
" -u --update Update target package(s)\n" " -u, --update Update target package(s)\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -y --yes Assume yes to all questions\n" " -y, --yes Assume yes to all questions\n"
" -V --version Show XBPS version\n"); " -V, --version Show XBPS version\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }

View File

@ -40,16 +40,16 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-pkgdb [OPTIONS] [PKGNAME...]\n\n" "Usage: xbps-pkgdb [OPTIONS] [PKGNAME...]\n\n"
"OPTIONS\n" "OPTIONS\n"
" -a --all Process all packages\n" " -a, --all Process all packages\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -h --help Print usage help\n" " -h, --help Show usage\n"
" -m --mode <auto|manual|hold|unhold|repolock|repounlock>\n" " -m, --mode <auto|manual|hold|unhold|repolock|repounlock>\n"
" Change PKGNAME to this mode\n" " Change PKGNAME to this mode\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -u --update Update pkgdb to the latest format\n" " -u, --update Update pkgdb to the latest format\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -V --version Show XBPS version\n"); " -V, --version Show XBPS version\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -136,8 +136,10 @@ main(int argc, char **argv)
/* NOTREACHED */ /* NOTREACHED */
} }
} }
if (!update_format && !all && (argc == optind)) if (!update_format && !all && (argc == optind)) {
usage(true); usage(true);
/* NOTREACHED */
}
memset(&xh, 0, sizeof(xh)); memset(&xh, 0, sizeof(xh));
if (rootdir) if (rootdir)

View File

@ -38,38 +38,38 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-query [OPTIONS] MODE [ARGUMENTS]\n" "Usage: xbps-query [OPTIONS] MODE [ARGUMENTS]\n"
"\nOPTIONS\n" "\nOPTIONS\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -c --cachedir <dir> Path to cachedir\n" " -c, --cachedir <dir> Path to cachedir\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -h --help Print help usage\n" " -h, --help Show usage\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d\n" " -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -M --memory-sync Remote repository data is fetched and stored\n" " -M, --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n" " in memory, ignoring on-disk repodata archives\n"
" -p --property PROP[,...] Show properties for PKGNAME\n" " -p, --property PROP[,...] Show properties for PKGNAME\n"
" -R --repository Enable repository mode. This mode explicitly\n" " -R, --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n" " looks for packages in repositories\n"
" --repository=<url> Enable repository mode and add repository\n" " --repository=<url> Enable repository mode and add repository\n"
" to the top of the list. This option can be\n" " to the top of the list. This option can be\n"
" specified multiple times.\n" " specified multiple times\n"
" --regex Use Extended Regular Expressions to match\n" " --regex Use Extended Regular Expressions to match\n"
" --fulldeptree Full dependency tree for -x/--deps\n" " --fulldeptree Full dependency tree for -x/--deps\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -V --version Show XBPS version\n" " -V, --version Show XBPS version\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
"\nMODE\n" "\nMODE\n"
" -l --list-pkgs List installed packages\n" " -l, --list-pkgs List installed packages\n"
" -L --list-repos List registered repositories\n" " -L, --list-repos List registered repositories\n"
" -H --list-hold-pkgs List packages on hold state\n" " -H, --list-hold-pkgs List packages on hold state\n"
" --list-repolock-pkgs List repolocked packages\n" " --list-repolock-pkgs List repolocked packages\n"
" -m --list-manual-pkgs List packages installed explicitly\n" " -m, --list-manual-pkgs List packages installed explicitly\n"
" -O --list-orphans List package orphans\n" " -O, --list-orphans List package orphans\n"
" -o --ownedby FILE Search for package files by matching STRING or REGEX\n" " -o, --ownedby FILE Search for package files by matching STRING or REGEX\n"
" -S --show PKG Show information for PKG [default mode]\n" " -S, --show PKG Show information for PKG [default mode]\n"
" -s --search PKG Search for packages by matching PKG, STRING or REGEX\n" " -s, --search PKG Search for packages by matching PKG, STRING or REGEX\n"
" --cat=FILE PKG Print FILE from PKG binpkg to stdout\n" " --cat=FILE PKG Print FILE from PKG binpkg to stdout\n"
" -f --files PKG Show package files for PKG\n" " -f, --files PKG Show package files for PKG\n"
" -x --deps PKG Show dependencies for PKG\n" " -x, --deps PKG Show dependencies for PKG\n"
" -X --revdeps PKG Show reverse dependencies for PKG\n"); " -X, --revdeps PKG Show reverse dependencies for PKG\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -214,6 +214,7 @@ main(int argc, char **argv)
list_repolock = opmode = true; list_repolock = opmode = true;
break; break;
case '?': case '?':
default:
usage(true); usage(true);
/* NOTREACHED */ /* NOTREACHED */
} }
@ -223,6 +224,7 @@ main(int argc, char **argv)
if (!argc && !opmode) { if (!argc && !opmode) {
usage(true); usage(true);
/* NOTREACHED */
} else if (!opmode) { } else if (!opmode) {
/* show mode by default */ /* show mode by default */
show = opmode = true; show = opmode = true;
@ -232,6 +234,7 @@ main(int argc, char **argv)
if (argc) { if (argc) {
/* trailing parameters */ /* trailing parameters */
usage(true); usage(true);
/* NOTREACHED */
} }
/* /*
* Initialize libxbps. * Initialize libxbps.

View File

@ -39,15 +39,15 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-reconfigure [OPTIONS] [PKGNAME...]\n\n" "Usage: xbps-reconfigure [OPTIONS] [PKGNAME...]\n\n"
"OPTIONS\n" "OPTIONS\n"
" -a --all Process all packages\n" " -a, --all Process all packages\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -f --force Force reconfiguration\n" " -f, --force Force reconfiguration\n"
" -h --help Print usage help\n" " -h, --help Show usage\n"
" -i --ignore PKG Ignore PKG with -a/--all\n" " -i, --ignore PKG Ignore PKG with -a/--all\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -V --version Show XBPS version\n"); " -V, --version Show XBPS version\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -147,8 +147,10 @@ main(int argc, char **argv)
/* NOTREACHED */ /* NOTREACHED */
} }
} }
if (!all && (argc == optind)) if (!all && (argc == optind)) {
usage(true); usage(true);
/* NOTREACHED */
}
memset(&xh, 0, sizeof(xh)); memset(&xh, 0, sizeof(xh));
xh.state_cb = state_cb; xh.state_cb = state_cb;

View File

@ -45,21 +45,21 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-remove [OPTIONS] [PKGNAME...]\n\n" "Usage: xbps-remove [OPTIONS] [PKGNAME...]\n\n"
"OPTIONS\n" "OPTIONS\n"
" -C --config <dir> Path to confdir (xbps.d)\n" " -C, --config <dir> Path to confdir (xbps.d)\n"
" -c --cachedir <dir> Path to cachedir\n" " -c, --cachedir <dir> Path to cachedir\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -F --force-revdeps Force package removal even with revdeps or\n" " -F, --force-revdeps Force package removal even with revdeps or\n"
" unresolved shared libraries\n" " unresolved shared libraries\n"
" -f --force Force package files removal\n" " -f, --force Force package files removal\n"
" -h --help Print help usage\n" " -h, --help Show usage\n"
" -n --dry-run Dry-run mode\n" " -n, --dry-run Dry-run mode\n"
" -O --clean-cache Remove obsolete packages in cachedir\n" " -O, --clean-cache Remove obsolete packages in cachedir\n"
" -o --remove-orphans Remove package orphans\n" " -o, --remove-orphans Remove package orphans\n"
" -R --recursive Recursively remove dependencies\n" " -R, --recursive Recursively remove dependencies\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r, --rootdir <dir> Full path to rootdir\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -y --yes Assume yes to all questions\n" " -y, --yes Assume yes to all questions\n"
" -V --version Show XBPS version\n"); " -V, --version Show XBPS version\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -236,8 +236,10 @@ main(int argc, char **argv)
/* NOTREACHED */ /* NOTREACHED */
} }
} }
if (!clean_cache && !orphans && (argc == optind)) if (!clean_cache && !orphans && (argc == optind)) {
usage(true); usage(true);
/* NOTREACHED */
}
/* /*
* Initialize libxbps. * Initialize libxbps.

View File

@ -37,21 +37,21 @@ usage(bool fail)
fprintf(stdout, fprintf(stdout,
"Usage: xbps-rindex [OPTIONS] MODE ARGUMENTS\n\n" "Usage: xbps-rindex [OPTIONS] MODE ARGUMENTS\n\n"
"OPTIONS\n" "OPTIONS\n"
" -d --debug Debug mode shown to stderr\n" " -d, --debug Debug mode shown to stderr\n"
" -f --force Force mode to overwrite entry in add mode\n" " -f, --force Force mode to overwrite entry in add mode\n"
" -h --help Show help usage\n" " -h, --help Show usage\n"
" -v --verbose Verbose messages\n" " -v, --verbose Verbose messages\n"
" -V --version Show XBPS version\n" " -V, --version Show XBPS version\n"
" -C --hashcheck Consider file hashes for cleaning up packages\n" " -C, --hashcheck Consider file hashes for cleaning up packages\n"
" --compression <fmt> Compression format: none, gzip, bzip2, lz4, xz, zstd (default).\n" " --compression <fmt> Compression format: none, gzip, bzip2, lz4, xz, zstd (default)\n"
" --privkey <key> Path to the private key for signing\n" " --privkey <key> Path to the private key for signing\n"
" --signedby <string> Signature details, i.e \"name <email>\"\n\n" " --signedby <string> Signature details, i.e \"name <email>\"\n\n"
"MODE\n" "MODE\n"
" -a --add <repodir/pkg> ... Add package(s) to repository index\n" " -a, --add <repodir/file.xbps> ... Add package(s) to repository index\n"
" -c --clean <repodir> Clean repository index\n" " -c, --clean <repodir> Clean repository index\n"
" -r --remove-obsoletes <repodir> Removes obsolete packages from repository\n" " -r, --remove-obsoletes <repodir> Removes obsolete packages from repository\n"
" -s --sign <repodir> Initialize repository metadata signature\n" " -s, --sign <repodir> Initialize repository metadata signature\n"
" -S --sign-pkg archive.xbps ... Sign binary package archive\n\n"); " -S, --sign-pkg <file.xbps> ... Sign binary package archive\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -130,11 +130,16 @@ main(int argc, char **argv)
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case '?':
default:
usage(true);
/* NOTREACHED */
} }
} }
if ((argc == optind) || if ((argc == optind) ||
(!add_mode && !clean_mode && !rm_mode && !sign_mode && !sign_pkg_mode)) { (!add_mode && !clean_mode && !rm_mode && !sign_mode && !sign_pkg_mode)) {
usage(true); usage(true);
/* NOTREACHED */
} else if ((add_mode && (clean_mode || rm_mode || sign_mode || sign_pkg_mode)) || } else if ((add_mode && (clean_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
(clean_mode && (add_mode || rm_mode || sign_mode || sign_pkg_mode)) || (clean_mode && (add_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
(rm_mode && (add_mode || clean_mode || sign_mode || sign_pkg_mode)) || (rm_mode && (add_mode || clean_mode || sign_mode || sign_pkg_mode)) ||

View File

@ -87,7 +87,7 @@ static SIMPLEQ_HEAD(bindmnt_head, bindmnt) bindmnt_queue =
SIMPLEQ_HEAD_INITIALIZER(bindmnt_queue); SIMPLEQ_HEAD_INITIALIZER(bindmnt_queue);
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(const char *p) usage(const char *p, bool fail)
{ {
printf("Usage: %s [OPTIONS] [--] <dir> <cmd> [<cmdargs>]\n\n" printf("Usage: %s [OPTIONS] [--] <dir> <cmd> [<cmdargs>]\n\n"
"-B, --bind-ro <src:dest> Bind mounts <src> into <dir>/<dest> (read-only)\n" "-B, --bind-ro <src:dest> Bind mounts <src> into <dir>/<dest> (read-only)\n"
@ -96,8 +96,8 @@ usage(const char *p)
"-t, --tmpfs Creates a tempdir and mounts <dir> on tmpfs (for use with -O)\n" "-t, --tmpfs Creates a tempdir and mounts <dir> on tmpfs (for use with -O)\n"
"-o, --options <opts> Options to be passed to the tmpfs mount (for use with -t)\n" "-o, --options <opts> Options to be passed to the tmpfs mount (for use with -t)\n"
"-V, --version Show XBPS version\n" "-V, --version Show XBPS version\n"
"-h, --help Show usage\n\n", p); "-h, --help Show usage\n", p);
exit(EXIT_FAILURE); exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
@ -369,16 +369,21 @@ main(int argc, char **argv)
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h': case 'h':
usage(argv0, false);
/* NOTREACHED */
case '?': case '?':
default: default:
usage(argv0); usage(argv0, true);
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc < 2) if (argc < 2) {
usage(argv0); usage(argv0, true);
/* NOTREACHED */
}
rootdir = argv[0]; rootdir = argv[0];
cmd = argv[1]; cmd = argv[1];

View File

@ -74,11 +74,14 @@ die(const char *fmt, ...)
} }
static void __attribute__((noreturn)) static void __attribute__((noreturn))
usage(const char *p) usage(const char *p, bool fail)
{ {
printf("Usage: %s [-b src:dest] [--] <dir> <cmd> [<cmdargs>]\n\n" printf("Usage: %s [OPTIONS] [--] <dir> <cmd> [<cmdargs>]\n\n"
"-b src:dest Bind mounts <src> into <dir>/<dest> (may be specified multiple times)\n\n", p); "OPTIONS\n"
exit(EXIT_FAILURE); " -b, --bind-rw <src:dest> Bind mounts <src> into <dir>/<dest> (read-write)\n"
" -h, --help Show usage\n"
" -V, --version Show XBPS version\n", p);
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
} }
static void static void
@ -130,13 +133,16 @@ main(int argc, char **argv)
char **cmdargs, buf[32]; char **cmdargs, buf[32];
int c, fd; int c, fd;
const struct option longopts[] = { const struct option longopts[] = {
{ "bind-rw", required_argument, NULL, 'b' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
}; };
chrootdir = cmd = NULL; chrootdir = cmd = NULL;
argv0 = argv[0]; argv0 = argv[0];
while ((c = getopt_long(argc, argv, "b:V", longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, "b:hV", longopts, NULL)) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
if (optarg == NULL || *optarg == '\0') if (optarg == NULL || *optarg == '\0')
@ -146,16 +152,22 @@ main(int argc, char **argv)
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'h':
usage(argv0, false);
/* NOTREACHED */
case '?': case '?':
default: default:
usage(argv0); usage(argv0, true);
/* NOTREACHED */
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc < 2) if (argc < 2) {
usage(argv0); usage(argv0, true);
/* NOTREACHED */
}
chrootdir = argv[0]; chrootdir = argv[0];
cmd = argv[1]; cmd = argv[1];