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
This commit is contained in:
parent
b5b26630e9
commit
50fb2017d0
@ -46,6 +46,7 @@ usage(void)
|
||||
" -C --config <dir> Path to confdir (xbps.d)\n"
|
||||
" -d --debug Debug mode shown to stderr\n"
|
||||
" -r --rootdir <dir> 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)
|
||||
|
@ -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 ...
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user