Skip to content

Commit

Permalink
bin: sync usage and keep it consistent in all utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan RP committed Apr 20, 2020
1 parent d5251a9 commit 9b69543
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 232 deletions.
4 changes: 2 additions & 2 deletions bin/xbps-alternatives/main.c
Expand Up @@ -44,13 +44,13 @@ usage(bool fail)
" -C --config <dir> Path to confdir (xbps.d)\n"
" -d --debug Debug mode shown to stderr\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"
" -v --verbose Verbose messages\n"
" -V --version Show XBPS version\n"
"MODE\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);
}

Expand Down
42 changes: 21 additions & 21 deletions bin/xbps-checkvers/main.c
Expand Up @@ -73,29 +73,28 @@ xstrdup(const char *src)
}

static int
show_usage(const char *prog)
show_usage(const char *prog, bool fail)
{
fprintf(stderr,
"Usage: %s [OPTIONS] [FILES...]\n\n"
"OPTIONS:\n"
" -h --help Show this helpful help-message for help.\n"
" -C --config <dir> Set path to xbps.d\n"
" -D --distdir <dir> Set (or override) the path to void-packages\n"
" (defaults to ~/void-packages).\n"
" -d --debug Enable debug output to stderr.\n"
" -e --removed List packages present in repos, but not in distdir.\n"
" -f --format <fmt> Output format.\n"
" -I --installed Check for outdated packages in rootdir, rather\n"
" than in the XBPS repositories.\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d.\n"
" -m --manual Only process listed files.\n"
" -R --repository=<url> Append repository to the head of repository list.\n"
" -r --rootdir <dir> Set root directory (defaults to /).\n"
" -s --show-all List all packages, in the format 'pkgname repover srcver'.\n"
"\n [FILES...] Extra packages to process with the outdated\n"
" ones (only processed if missing).\n\n",
prog);
return EXIT_FAILURE;
" -h, --help Show usage\n"
" -C, --config <dir> Set path to xbps.d\n"
" -D, --distdir <dir> Set (or override) the path to void-packages\n"
" (defaults to ~/void-packages)\n"
" -d, --debug Enable debug output to stderr\n"
" -e, --removed List packages present in repos, but not in distdir\n"
" -f, --format <fmt> Output format\n"
" -I, --installed Check for outdated packages in rootdir, rather\n"
" than in the XBPS repositories\n"
" -i, --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -m, --manual Only process listed files\n"
" -R, --repository=<url> Append repository to the head of repository list\n"
" -r, --rootdir <dir> Set root directory (defaults to /)\n"
" -s, --show-all List all packages, in the format 'pkgname repover srcver'\n"
"\n [FILES...] Extra packages to process with the outdated\n"
" ones (only processed if missing).\n", prog);
return fail ? EXIT_FAILURE: EXIT_SUCCESS;
}

static void
Expand Down Expand Up @@ -728,7 +727,7 @@ main(int argc, char **argv)
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
switch (c) {
case 'h':
return show_usage(prog);
return show_usage(prog, false);
case 'C':
rcv.xbps_conf = xstrdup(optarg);
break;
Expand Down Expand Up @@ -765,8 +764,9 @@ main(int argc, char **argv)
case 'V':
printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS);
case '?':
default:
return show_usage(prog);
return show_usage(prog, true);
}
}
/*
Expand Down
84 changes: 41 additions & 43 deletions bin/xbps-create/main.c
Expand Up @@ -68,54 +68,49 @@ static xbps_dictionary_t pkg_propsd, pkg_filesd, all_filesd;
static const char *destdir;

static void __attribute__((noreturn))
usage(void)
usage(bool fail)
{
fprintf(stdout,
"Usage: %s [OPTIONS] -A <arch> -n <pkgver> -s \"<desc>\" destdir\n\n"
"OPTIONS\n"
" -A --architecture Package architecture (e.g: noarch, i686, etc).\n"
" -B --built-with Package builder string (e.g: xbps-src-30).\n"
" -C --conflicts Conflicts (blank separated list,\n"
" e.g: 'foo>=2.0 blah<=2.0').\n"
" -c --changelog Changelog URL.\n"
" -D --dependencies Dependencies (blank separated list,\n"
" e.g: 'foo>=1.0_1 blah<2.1').\n"
" -F --config-files Configuration files (blank separated list,\n"
" e.g '/etc/foo.conf /etc/foo-blah.conf').\n"
" -H --homepage Homepage.\n"
" -h --help Show help.\n"
" -l --license License.\n"
" -M --mutable-files Mutable files list (blank separated list,\n"
" e.g: '/usr/lib/foo /usr/bin/blah').\n"
" -m --maintainer Maintainer.\n"
" -n --pkgver Package name/version tuple (e.g `foo-1.0_1').\n"
" -P --provides Provides (blank separated list,\n"
" e.g: 'foo-9999 blah-1.0').\n"
" -p --preserve Enable package preserve boolean.\n"
" -q --quiet Work silently.\n"
" -R --replaces Replaces (blank separated list,\n"
" e.g: 'foo>=1.0 blah<2.0').\n"
" -r --reverts Reverts (blank separated list,\n"
" e.g: '1.0_1 2.0_3').\n"
" -S --long-desc Long description (80 cols per line).\n"
" -s --desc Short description (max 80 characters).\n"
" -t --tags A list of tags/categories (blank separated list).\n"
" -V --version Prints XBPS release version.\n"
" --alternatives List of available alternatives this pkg provides.\n"
" This expects a blank separated list of <name>:<symlink>:<target>, e.g\n"
" 'vi:/usr/bin/vi:/usr/bin/vim foo:/usr/bin/foo:/usr/bin/blah'.\n"
" --build-options A string with the used build options.\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"
" -A, --architecture Package architecture (e.g: noarch, i686, etc)\n"
" -B, --built-with Package builder string (e.g: xbps-src-30)\n"
" -C, --conflicts Conflicts (blank separated list, e.g: 'foo>=2.0 blah<=2.0')\n"
" -c, --changelog Changelog URL\n"
" -D, --dependencies Dependencies (blank separated list, e.g: 'foo>=1.0_1 blah<2.1')\n"
" -F, --config-files Configuration files (blank separated list,\n"
" e.g '/etc/foo.conf /etc/foo-blah.conf')\n"
" -H, --homepage Homepage\n"
" -h, --help Show usage\n"
" -l, --license License\n"
" -M, --mutable-files Mutable files list (blank separated list,\n"
" e.g: '/usr/lib/foo /usr/bin/blah')\n"
" -m, --maintainer Maintainer\n"
" -n, --pkgver Package name/version tuple (e.g `foo-1.0_1')\n"
" -P, --provides Provides (blank separated list, e.g: 'foo-9999 blah-1.0')\n"
" -p, --preserve Enable package preserve boolean\n"
" -q, --quiet Work silently\n"
" -R, --replaces Replaces (blank separated list, e.g: 'foo>=1.0 blah<2.0')\n"
" -r, --reverts Reverts (blank separated list, e.g: '1.0_1 2.0_3')\n"
" -S, --long-desc Long description (80 cols per line)\n"
" -s, --desc Short description (max 80 characters)\n"
" -t, --tags A list of tags/categories (blank separated list)\n"
" -V, --version Show XBPS version\n"
" --alternatives List of available alternatives this pkg provides\n"
" This expects a blank separated list of <name>:<symlink>:<target>, e.g\n"
" 'vi:/usr/bin/vi:/usr/bin/vim foo:/usr/bin/foo:/usr/bin/blah'\n"
" --build-options A string with the used build options\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"
" At least three flags are required: architecture, pkgver and desc.\n\n"
"EXAMPLE:\n"
" $ %s -A noarch -n foo-1.0_1 -s \"foo pkg\" destdir\n",
_PROGNAME, _PROGNAME);
exit(EXIT_FAILURE);
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
}

static void __attribute__((noreturn))
Expand Down Expand Up @@ -866,7 +861,7 @@ main(int argc, char **argv)
srcrevs = optarg;
break;
case 'h':
usage();
usage(false);
break;
case 'H':
homepage = optarg;
Expand Down Expand Up @@ -927,11 +922,14 @@ main(int argc, char **argv)
break;
case '?':
default:
usage();
usage(true);
/* NOTREACHED */
}
}
if (argc == optind)
usage();
if (argc == optind) {
usage(true);
/* NOTREACHED */
}

destdir = argv[optind];

Expand Down
37 changes: 21 additions & 16 deletions bin/xbps-dgraph/main.c
Expand Up @@ -110,25 +110,25 @@ die(const char *fmt, ...)
}

static void __attribute__((noreturn))
usage(void)
usage(bool fail)
{
fprintf(stdout,
"Usage: xbps-dgraph [OPTIONS] [MODE] <pkgname>\n\n"
"OPTIONS\n"
" -C --config <dir> Path to confdir (xbps.d)\n"
" -c --graph-config <file> Path to the graph configuration file\n"
" -d --debug Debug mode shown to stderr\n"
" -h --help Print help usage\n"
" -M --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n"
" -r --rootdir <dir> Full path to rootdir\n"
" -R --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n"
" -C, --config <dir> Path to confdir (xbps.d)\n"
" -c, --graph-config <file> Path to the graph configuration file\n"
" -d, --debug Debug mode shown to stderr\n"
" -h, --help Show usage\n"
" -M, --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n"
" -r, --rootdir <dir> Full path to rootdir\n"
" -R, --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n"
"MODE\n"
" -g --gen-config Generate a configuration file\n"
" -f --fulldeptree Generate a dependency graph\n"
" -m --metadata Generate a metadata graph (default mode)\n\n");
exit(EXIT_FAILURE);
" -g, --gen-config Generate a configuration file\n"
" -f, --fulldeptree Generate a dependency graph\n"
" -m, --metadata Generate a metadata graph (default mode)\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
}

static const char *
Expand Down Expand Up @@ -558,6 +558,9 @@ main(int argc, char **argv)
/* Generate conf file. */
generate_conf_file();
exit(EXIT_SUCCESS);
case 'h':
usage(false);
/* NOTREACHED */
case 'M':
flags |= XBPS_FLAG_REPOS_MEMSYNC;
break;
Expand All @@ -578,15 +581,17 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
case '?':
default:
usage();
usage(true);
/* NOTREACHED */
}
}

argc -= optind;
argv += optind;

if (!argc && !opmode) {
usage();
usage(true);
/* NOTREACHED */
}
pkg = *argv;

Expand Down
27 changes: 16 additions & 11 deletions bin/xbps-digest/main.c
Expand Up @@ -34,19 +34,18 @@
#include <xbps.h>

static void __attribute__((noreturn))
usage(void)
usage(bool fail)
{
fprintf(stdout,
"Usage: xbps-digest [options] [file] [file+N]\n"
"\n"
"OPTIONS:\n"
" -h\t\tShow usage()\n"
" -m <sha256>\tSelects the digest mode, sha256 (default)\n"
" -V\t\tPrints the xbps release version\n"
"\n"
"NOTES\n"
" If [file] not set, reads from stdin.\n");
exit(EXIT_FAILURE);
"OPTIONS\n"
" -h, --help Show usage\n"
" -m, --mode <sha256> Selects the digest mode, sha256 (default)\n"
" -V, --version Show XBPS version\n"
"\nNOTES\n"
" If [file] not set, reads from stdin\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
}

int
Expand All @@ -56,21 +55,27 @@ main(int argc, char **argv)
char sha256[XBPS_SHA256_SIZE];
const char *mode = NULL, *progname = argv[0];
const struct option longopts[] = {
{ "mode", required_argument, NULL, 'm' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};

while ((c = getopt_long(argc, argv, "m:hV", longopts, NULL)) != -1) {
switch (c) {
case 'h':
usage(false);
/* NOTREACHED */
case 'm':
mode = optarg;
break;
case 'V':
printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS);
case '?':
case 'h':
default:
usage();
usage(true);
/* NOTREACHED */
}
}

Expand Down
17 changes: 10 additions & 7 deletions bin/xbps-fbulk/main.c
Expand Up @@ -132,7 +132,7 @@ addItem(const char *pkgn)
}

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"
"OPTIONS\n"
Expand All @@ -142,7 +142,7 @@ usage(const char *progname)
" -V, --verbose Enable verbose mode\n"
" -v, --version Show XBPS version\n"
" -h, --help Show usage\n", progname);
exit(EXIT_FAILURE);
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
}

/*
Expand Down Expand Up @@ -577,6 +577,9 @@ main(int argc, char **argv)

while ((ch = getopt_long(argc, argv, "hj:l:svV", longopts, NULL)) != -1) {
switch (ch) {
case 'h':
usage(progname, false);
/* NOTREACHED */
case 's':
RebuildSystem = true;
break;
Expand All @@ -592,18 +595,18 @@ main(int argc, char **argv)
case 'V':
printf("%s\n", XBPS_RELVER);
exit(EXIT_SUCCESS);
case 'h':
case '?':
default:
usage(progname);
/* NOT REACHED */
usage(progname, true);
/* NOTREACHED */
}
}
argc -= optind;
argv += optind;

if (argc < 1) {
usage(progname);
/* NOT REACHED */
usage(progname, true);
/* NOTREACHED */
}

/*
Expand Down

0 comments on commit 9b69543

Please sign in to comment.