repo-parse: remove unused import
[aurutils.git] / lib / aur-query
blobd2783c9b3378ca82381702bf5a94a04250158829
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use v5.20;
6 use AUR::Query qw(query query_multi);
7 use AUR::Options qw(add_from_stdin);
8 my $argv0 = 'query';
10 unless (caller) {
11 # option handling
12 use Getopt::Long;
13 my $opt_by;
14 my $opt_type = "";
16 GetOptions(
17 't|type=s' => \$opt_type,
18 'b|by=s' => \$opt_by,
19 'r|raw' => sub { } # noop
20 ) or exit(1);
22 if (not length($opt_type)) {
23 say STDERR "$argv0: type must be specified";
24 exit(1);
27 if (not scalar(@ARGV)) {
28 say STDERR "$argv0: at least one argument required";
29 exit(1);
31 # Handle '-' to take packages from stdin
32 add_from_stdin(\@ARGV, ['-', '/dev/stdin']);
34 # Exit gracefully on empty stdin, e.g. when piping from `aur repo -u`
35 if (not scalar(@ARGV)) {
36 exit(0);
38 my %query_args = (type => $opt_type, by => $opt_by, callback => sub { say @_ });
40 # search requests take a single argument only
41 if ($opt_type eq "search" or $opt_type eq "suggest" or $opt_type eq "suggest-pkgbase") {
42 map { query(term => $_, %query_args) } @ARGV;
43 } else {
44 query_multi(terms => \@ARGV, %query_args);
48 # vim: set et sw=4 sts=4 ft=perl: