texlive[71056] Master/texmf-dist/scripts/texlive/tlmgr.pl: tlmgr
commits+preining at tug.org
commits+preining at tug.org
Wed Apr 24 14:09:11 CEST 2024
Revision: 71056
https://tug.org/svn/texlive?view=revision&revision=71056
Author: preining
Date: 2024-04-24 14:09:11 +0200 (Wed, 24 Apr 2024)
Log Message:
-----------
tlmgr search: support --json
Modified Paths:
--------------
trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
Modified: trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl
===================================================================
--- trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl 2024-04-24 11:59:16 UTC (rev 71055)
+++ trunk/Master/texmf-dist/scripts/texlive/tlmgr.pl 2024-04-24 12:09:11 UTC (rev 71056)
@@ -1843,14 +1843,30 @@
$tlpdb = $localtlpdb;
}
- my ($foundfile, $founddesc) = search_tlpdb($tlpdb, $r,
+ my $ret = search_tlpdb($tlpdb, $r,
$opts{'file'} || $opts{'all'},
(!$opts{'file'} || $opts{'all'}),
$opts{'word'});
-
- print $founddesc;
- print $foundfile;
+ if ($opts{'json'}) {
+ my $json = TeXLive::TLUtils::encode_json($ret);
+ print($json);
+ } else {
+ my $retfile = '';
+ my $retdesc = '';
+ for my $pkg (sort keys %{$ret->{"packages"}}) {
+ $retdesc .= "$pkg - " . $ret->{"packages"}{$pkg} . "\n";
+ }
+ for my $pkg (sort keys %{$ret->{"files"}}) {
+ $retfile .= "$pkg:\n";
+ for my $f (@{$ret->{"files"}{$pkg}}) {
+ $retfile .= "\t$f\n";
+ }
+ }
+ print ($retdesc);
+ print ($retfile);
+ }
+
return ($F_OK | $F_NOPOSTACTION);
}
@@ -1896,20 +1912,24 @@
# first report on $pkg - $shortdesc found
my $retfile = '';
my $retdesc = '';
+ my %ret = ( "packages" => {}, "files" => {} );
for my $pkg (sort keys %$fndptr) {
if ($fndptr->{$pkg}{'desc'}) {
- $retdesc .= "$pkg - " . $fndptr->{$pkg}{'desc'} . "\n";
+ $ret{"packages"}{$pkg} = $fndptr->{$pkg}{'desc'};
}
}
for my $pkg (sort keys %$fndptr) {
if ($fndptr->{$pkg}{'files'}) {
- $retfile .= "$pkg:\n";
- for my $f (keys %{$fndptr->{$pkg}{'files'}}) {
- $retfile .= "\t$f\n";
- }
+ $ret{"files"}{$pkg} = [ keys %{$fndptr->{$pkg}{'files'}} ];
}
}
- return($retfile, $retdesc);
+ # {
+ # require Data::Dumper;
+ # print Data::Dumper->Dump([\%retjson], [qw(retjson)]);
+ # my $json = TeXLive::TLUtils::encode_json(\%retjson);
+ # print($json);
+ # }
+ return (\%ret);
}
sub search_pkg_files {
@@ -9467,6 +9487,11 @@
C<table> with this option will not output packages containing the word
C<tables> (unless they also contain the word C<table> on its own).
+=item B<--json>
+
+Output search results as json hash with two keys: B<files> and B<packages>.
+
+
=back
=back
More information about the tex-live-commits
mailing list.