From 50fb2017d0c05867a189e762c7193c4ad00dda35 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 29 Mar 2023 16:04:38 -0400 Subject: [PATCH] xbps-uhelper: add verbose output for cmpver/pkgmatch I can never remember which retval means which thing. This only prints if -v/--verbose is specified. Examples: ``` $ ./bin/xbps-uhelper/xbps-uhelper -v cmpver 1 2 ; echo ret: $? 1 < 2 ret: 255 $ ./bin/xbps-uhelper/xbps-uhelper -v cmpver 1 1 ; echo ret: $? 1 = 1 ret: 0 $ ./bin/xbps-uhelper/xbps-uhelper -v cmpver 2 1 ; echo ret: $? 2 > 1 ret: 1 $ ./bin/xbps-uhelper/xbps-uhelper -v pkgmatch 'foo-1.0_1' 'foo>=0' ; echo ret: $? foo-1.0_1 matches foo>=0 ret: 1 $ ./bin/xbps-uhelper/xbps-uhelper -v pkgmatch 'foo-1.0_1' 'foo<0.1_1' ; echo ret: $? foo-1.0_1 does not match foo<0.1_1 ret: 0 ``` it also seems that getting an error from pkgmatch is currently impossible --- bin/xbps-uhelper/main.c | 28 ++++++++++++++++++++++++---- bin/xbps-uhelper/xbps-uhelper.1 | 19 +++++++++++++++++++ data/_xbps | 5 +---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index cb9922b9..84eca5bf 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -46,6 +46,7 @@ usage(void) " -C --config Path to confdir (xbps.d)\n" " -d --debug Debug mode shown to stderr\n" " -r --rootdir Full path to rootdir\n" + " -v --verbose Verbose messages\n" " -V --version Show XBPS verison\n" "\n" "MODE\n" @@ -96,11 +97,12 @@ main(int argc, char **argv) { "config", required_argument, NULL, 'C' }, { "debug", no_argument, NULL, 'd' }, { "rootdir", required_argument, NULL, 'r' }, + { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argc, argv, "C:dr:V", longopts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "C:dr:vV", longopts, NULL)) != -1) { switch (c) { case 'C': confdir = optarg; @@ -112,6 +114,9 @@ main(int argc, char **argv) case 'd': flags |= XBPS_FLAG_DEBUG; break; + case 'v': + flags |= XBPS_FLAG_VERBOSE; + break; case 'V': printf("%s\n", XBPS_RELVER); exit(EXIT_SUCCESS); @@ -318,14 +323,29 @@ main(int argc, char **argv) /* Matches a pkg with a pattern */ if (argc != 3) usage(); - - exit(xbps_pkgpattern_match(argv[1], argv[2])); + rv = xbps_pkgpattern_match(argv[1], argv[2]); + if (flags & XBPS_FLAG_VERBOSE) { + if (rv >= 0) + fprintf(stderr, "%s %s %s\n", + argv[1], + (rv == 1) ? "matches" : "does not match", + argv[2]); + else + xbps_error_printf("%s: not a pattern\n", argv[2]); + } + exit(rv); } else if (strcmp(argv[0], "cmpver") == 0) { /* Compare two version strings, installed vs required */ if (argc != 3) usage(); - exit(xbps_cmpver(argv[1], argv[2])); + rv = xbps_cmpver(argv[1], argv[2]); + if (flags & XBPS_FLAG_VERBOSE) + fprintf(stderr, "%s %s %s\n", + argv[1], + (rv == 1) ? ">" : ((rv == 0) ? "=" : "<"), + argv[2]); + exit(rv); } else if (strcmp(argv[0], "arch") == 0) { /* returns the xbps native arch */ if (argc != 1) diff --git a/bin/xbps-uhelper/xbps-uhelper.1 b/bin/xbps-uhelper/xbps-uhelper.1 index bc2edabb..57acc44c 100644 --- a/bin/xbps-uhelper/xbps-uhelper.1 +++ b/bin/xbps-uhelper/xbps-uhelper.1 @@ -59,6 +59,8 @@ Enables extra debugging shown to stderr. Show the help message. .It Fl r, Fl -rootdir Ar dir Specifies a full path for the target root directory. +.It Fl v, Fl -verbose +Enables verbose messages. .It Fl V, Fl -version Show the version information. .El @@ -85,6 +87,14 @@ strings, See .Sx EXIT STATUS for more information. +If +.Fl -verbose +is specified, also prints +.Qo +.Ar instver +<|=|> +.Ar reqver +.Qc . .It Cm getname Ar string ... Prints the pkgname of .Ar pkgpatterns @@ -126,6 +136,15 @@ with a See .Sx EXIT STATUS for more information. +If +.Fl -verbose +is specified, also prints +.Qo +.Ar pkgver +matches|does not match +.Ar pkgpattern +.Qc , +or an error. .It Cm real-version Ar pkgname ... Prints the version of installed real packages. .It Cm version Ar pkgname ... diff --git a/data/_xbps b/data/_xbps index 31587571..449f6cc0 100644 --- a/data/_xbps +++ b/data/_xbps @@ -229,10 +229,7 @@ _xbps_uchroot() { _xbps_uhelper() { local ret=1 _arguments \ - {-C,--config=-}'[Full path to configuration file]:config file:_files' \ - {-d,--debug}'[Debug mode shown to stderr]' \ - {-r,--rootdir=-}'[Full path to rootdir]:root dir:_files -/' \ - {-V,--version}'[Show XBPS version]' \ + $_xbps_common \ '1:action:->actions' \ '*:: :->args' && ret=0 case $state in