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"
|
" -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"
|
||||||
" -r --rootdir <dir> Full path to rootdir\n"
|
" -r --rootdir <dir> Full path to rootdir\n"
|
||||||
|
" -v --verbose Verbose messages\n"
|
||||||
" -V --version Show XBPS verison\n"
|
" -V --version Show XBPS verison\n"
|
||||||
"\n"
|
"\n"
|
||||||
"MODE\n"
|
"MODE\n"
|
||||||
@ -96,11 +97,12 @@ main(int argc, char **argv)
|
|||||||
{ "config", required_argument, NULL, 'C' },
|
{ "config", required_argument, NULL, 'C' },
|
||||||
{ "debug", no_argument, NULL, 'd' },
|
{ "debug", no_argument, NULL, 'd' },
|
||||||
{ "rootdir", required_argument, NULL, 'r' },
|
{ "rootdir", required_argument, NULL, 'r' },
|
||||||
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ 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) {
|
switch (c) {
|
||||||
case 'C':
|
case 'C':
|
||||||
confdir = optarg;
|
confdir = optarg;
|
||||||
@ -112,6 +114,9 @@ main(int argc, char **argv)
|
|||||||
case 'd':
|
case 'd':
|
||||||
flags |= XBPS_FLAG_DEBUG;
|
flags |= XBPS_FLAG_DEBUG;
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
flags |= XBPS_FLAG_VERBOSE;
|
||||||
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("%s\n", XBPS_RELVER);
|
printf("%s\n", XBPS_RELVER);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -318,14 +323,29 @@ main(int argc, char **argv)
|
|||||||
/* Matches a pkg with a pattern */
|
/* Matches a pkg with a pattern */
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage();
|
usage();
|
||||||
|
rv = xbps_pkgpattern_match(argv[1], argv[2]);
|
||||||
exit(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) {
|
} else if (strcmp(argv[0], "cmpver") == 0) {
|
||||||
/* Compare two version strings, installed vs required */
|
/* Compare two version strings, installed vs required */
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
usage();
|
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) {
|
} else if (strcmp(argv[0], "arch") == 0) {
|
||||||
/* returns the xbps native arch */
|
/* returns the xbps native arch */
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
|
@ -59,6 +59,8 @@ Enables extra debugging shown to stderr.
|
|||||||
Show the help message.
|
Show the help message.
|
||||||
.It Fl r, Fl -rootdir Ar dir
|
.It Fl r, Fl -rootdir Ar dir
|
||||||
Specifies a full path for the target root directory.
|
Specifies a full path for the target root directory.
|
||||||
|
.It Fl v, Fl -verbose
|
||||||
|
Enables verbose messages.
|
||||||
.It Fl V, Fl -version
|
.It Fl V, Fl -version
|
||||||
Show the version information.
|
Show the version information.
|
||||||
.El
|
.El
|
||||||
@ -85,6 +87,14 @@ strings,
|
|||||||
See
|
See
|
||||||
.Sx EXIT STATUS
|
.Sx EXIT STATUS
|
||||||
for more information.
|
for more information.
|
||||||
|
If
|
||||||
|
.Fl -verbose
|
||||||
|
is specified, also prints
|
||||||
|
.Qo
|
||||||
|
.Ar instver
|
||||||
|
<|=|>
|
||||||
|
.Ar reqver
|
||||||
|
.Qc .
|
||||||
.It Cm getname Ar string ...
|
.It Cm getname Ar string ...
|
||||||
Prints the pkgname of
|
Prints the pkgname of
|
||||||
.Ar pkgpatterns
|
.Ar pkgpatterns
|
||||||
@ -126,6 +136,15 @@ with a
|
|||||||
See
|
See
|
||||||
.Sx EXIT STATUS
|
.Sx EXIT STATUS
|
||||||
for more information.
|
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 ...
|
.It Cm real-version Ar pkgname ...
|
||||||
Prints the version of installed real packages.
|
Prints the version of installed real packages.
|
||||||
.It Cm version Ar pkgname ...
|
.It Cm version Ar pkgname ...
|
||||||
|
@ -229,10 +229,7 @@ _xbps_uchroot() {
|
|||||||
_xbps_uhelper() {
|
_xbps_uhelper() {
|
||||||
local ret=1
|
local ret=1
|
||||||
_arguments \
|
_arguments \
|
||||||
{-C,--config=-}'[Full path to configuration file]:config file:_files' \
|
$_xbps_common \
|
||||||
{-d,--debug}'[Debug mode shown to stderr]' \
|
|
||||||
{-r,--rootdir=-}'[Full path to rootdir]:root dir:_files -/' \
|
|
||||||
{-V,--version}'[Show XBPS version]' \
|
|
||||||
'1:action:->actions' \
|
'1:action:->actions' \
|
||||||
'*:: :->args' && ret=0
|
'*:: :->args' && ret=0
|
||||||
case $state in
|
case $state in
|
||||||
|
Loading…
Reference in New Issue
Block a user